Esempio n. 1
0
def main(args):
    rs=[]
    for i in range(1,repeat):
        print('doing{}'.format(i))
        test_loader = custom_data_loader.benchmarkLoader(args)
        model    = custom_model.buildModel(args)
        # print(sum(p.numel() for p in model.parameters() if p.requires_grad))
        recorder = recorders.Records(args.log_dir)
        # r=test_utils.test_split2c(args, 'test', test_loader, model, log, 1, recorder, padding=4, stride=128)
        r=test_utils.test_split_rob(args, 'test', test_loader, model, log, 1, recorder, padding=16, stride=96, noise_level=i)
        # r=test_utils.test(args, 'test', test_loader, model, log, 1, recorder)
        r.append(np.mean(r))
        rs.append(np.stack(r))
    # test_utils.test(args, 'test', test_loader, model, log, 1, recorder)
    # rs=np.stack(rs)
    # every_mean=np.mean(rs,axis=0)
    # mean=np.mean(rs)
    # print(every_mean,mean)

    print(rs)
    # rs=np.stack(rs,axis=0)
    # rs=np.mean(rs,axis=0)

    workbook = xlwt.Workbook(encoding='ascii')
    worksheet = workbook.add_sheet('My Worksheet', cell_overwrite_ok=True)
    for i,r in zip(range(repeat),rs):
        for ii,rr in zip(range(10),r):
            worksheet.write(i + 1, ii, label=rr)
    workbook.save('result/robust/pro.xls')
Esempio n. 2
0
def main(args):
    model_s1 = custom_model.buildModel(args)
    model_s2 = custom_model.buildModelStage2(args)
    model_s3 = custom_model.buildModelStage3(args)
    model_s0 = custom_model.buildModelStage0(args)
    models = [model_s1, model_s2, model_s3, model_s0]

    #optimizer, scheduler, records = solver_utils.configMultiOptimizer(args, models)
    optimizer, scheduler, records = solver_utils.configMultiOptimizer(
        args, [models[1], models[2]])
    optimizers = [optimizer, -1]
    criterion = solver_utils.Stage4Crit(args)
    recorder = recorders.Records(args.log_dir, records)

    train_loader, val_loader = custom_data_loader.pokemonDataloader(args)

    for epoch in range(args.start_epoch, args.epochs + 1):
        scheduler.step()

        recorder.insertRecord('train', 'lr', epoch, scheduler.get_lr()[0])

        train_utils.train(args, train_loader, models, criterion, optimizers,
                          log, epoch, recorder)
        if epoch % args.save_intv == 0:
            model_utils.saveMultiCheckpoint(args.cp_dir, epoch, models,
                                            optimizer, recorder.records, args)
        #log.plotCurves(recorder, 'train')

        if epoch % args.val_intv == 0:
            test_utils.test(args, 'val', val_loader, models, log, epoch,
                            recorder)
Esempio n. 3
0
def main(args):
    rs = []
    for i in range(15, 16):
        # path="data/Training5shadow/checkp_{}.pth.tar".format(i)
        # args.retrain=path
        log = logger.Logger(args)
        test_loader = custom_data_loader.benchmarkLoader(args)
        model = custom_model.buildModel(args)
        # print(sum(p.numel() for p in model.parameters() if p.requires_grad))
        recorder = recorders.Records(args.log_dir)
        # r=test_utils.test_split2c(args, 'test', test_loader, model, log, 1, recorder, padding=4, stride=128)
        r = test_utils.test_split(args,
                                  'test',
                                  test_loader,
                                  model,
                                  log,
                                  1,
                                  recorder,
                                  padding=0,
                                  stride=64)
        rs.append(np.mean(r))
    # test_utils.test(args, 'test', test_loader, model, log, 1, recorder)
    # rs=np.stack(rs)
    # every_mean=np.mean(rs,axis=0)
    # mean=np.mean(rs)
    # print(every_mean,mean)

    print(rs)

    f = open('runlog.txt', 'w+')
    f.writelines(np.array2string(rs))
    f.close()
Esempio n. 4
0
def main(args):
    model = custom_model.buildModel(args)
    model_s2 = custom_model.buildModelStage2(args)
    models = [model, model_s2]

    optimizer, scheduler, records = solver_utils.configOptimizer(
        args, model_s2)
    optimizers = [optimizer, -1]
    criterion = solver_utils.Stage2Crit(args)
    recorder = recorders.Records(args.log_dir, records)

    train_loader, val_loader = custom_data_loader.customDataloader(args)

    for epoch in range(args.start_epoch, args.epochs + 1):
        scheduler.step()

        recorder.insertRecord('train', 'lr', epoch, scheduler.get_lr()[0])

        train_utils.train(args, train_loader, models, criterion, optimizers,
                          log, epoch, recorder)
        if epoch % args.save_intv == 0:
            model_utils.saveCheckpoint(args.cp_dir, epoch, model_s2, optimizer,
                                       recorder.records, args)
        log.plotCurves(recorder, 'train')

        if epoch % args.val_intv == 0:
            test_utils.test(args, 'val', val_loader, models, log, epoch,
                            recorder)
            log.plotCurves(recorder, 'val')
Esempio n. 5
0
def main(args):
    rs = []
    for i in range(repeat):
        args.in_img_num = -4 + i
        # path="data/Training5shadow/checkp_{}.pth.tar".format(i)
        # args.retrain=path
        log = logger.Logger(args)
        test_loader = custom_data_loader.benchmarkLoader(args)
        model = custom_model.buildModel(args)
        # print(sum(p.numel() for p in model.parameters() if p.requires_grad))
        recorder = recorders.Records(args.log_dir)
        # r=test_utils.test_split2c(args, 'test', test_loader, model, log, 1, recorder, padding=4, stride=128)
        r = test_utils.test_split(args,
                                  'test',
                                  test_loader,
                                  model,
                                  log,
                                  1,
                                  recorder,
                                  padding=10,
                                  stride=120)
        rs.append(r)
    # test_utils.test(args, 'test', test_loader, model, log, 1, recorder)
    # rs=np.stack(rs)
    # every_mean=np.mean(rs,axis=0)
    # mean=np.mean(rs)
    # print(every_mean,mean)

    print(rs)
    workbook = xlwt.Workbook(encoding='ascii')
    worksheet = workbook.add_sheet('My Worksheet', cell_overwrite_ok=True)
    for i, r in zip(range(repeat), rs):
        for ii, rr in zip(range(9), r):
            worksheet.write(i + 1, ii, label=rr)
    workbook.save('result/sparse/sparse_pro{}.xls'.format(i))
Esempio n. 6
0
def main(args):
    test_loader = custom_data_loader.benchmarkLoader(args)
    model = custom_model.buildModel(args)
    model_s2 = custom_model.buildModelStage2(args)
    models = [model, model_s2]

    recorder = recorders.Records(args.log_dir)
    test_utils.test(args, 'test', test_loader, models, log, 1, recorder)
Esempio n. 7
0
def main(args):
    rs=[]
    for i in range(5,6):
        # path="data/Training5shadow/checkp_{}.pth.tar".format(i)
        # args.retrain=path
        log = logger.Logger(args)
        test_loader = custom_data_loader.benchmarkLoader(args)
        model    = custom_model.buildModel(args)
        # print(sum(p.numel() for p in model.parameters() if p.requires_grad))
        recorder = recorders.Records(args.log_dir)
        # r=test_utils.test_split2c(args, 'test', test_loader, model, log, 1, recorder, padding=4, stride=128)
        test_utils.estimate(args, i, test_loader, model, log, 1, recorder, padding=4, stride=64, split=True)
Esempio n. 8
0
def main(args):
    rs = []
    # path="data/Training4shadow/checkp_{}.pth.tar".format(i)
    # args.retrain=path
    test_loader = custom_data_loader.benchmarkLoader(args)
    model = custom_model.buildModel(args)
    recorder = recorders.Records(args.log_dir)
    # r=test_utils.test_split(args, 'test', test_loader, model, log, 1, recorder, padding=4, stride=160)
    # errors=test_utils.test(args, 'test', test_loader, model, log, 1, recorder)
    errors = test_utils.test2c(args, 'test', test_loader, model, log, 1,
                               recorder)

    csvfile = open('names.csv', 'w', newline='')
    obj = csv.writer(csvfile)
    for person in errors:
        obj.writerow(person)
    csvfile.close()
Esempio n. 9
0
def main(args):
    train_loader, val_loader = custom_data_loader.customDataloader(args)

    model = custom_model.buildModel(args)
    optimizer, scheduler, records = solver_utils.configOptimizer(args, model)
    criterion = solver_utils.Criterion(args)
    recorder  = recorders.Records(args.log_dir, records)

    tf_train_writer, tf_test_writer = tfboard.tensorboard_init()

    for epoch in range(args.start_epoch, args.epochs+1):
        scheduler.step()
        recorder.insertRecord('train', 'lr', epoch, scheduler.get_lr()[0])

        train_utils.train(args, train_loader, model, criterion, optimizer, log, epoch, recorder, tf_train_writer)
        if epoch % args.save_intv == 0: 
            model_utils.saveCheckpoint(args.cp_dir, epoch, model, optimizer, recorder.records, args)

        if epoch % args.val_intv == 0:
            test_utils.test(args, 'val', val_loader, model, log, epoch, recorder, tf_test_writer)
Esempio n. 10
0
def main(args):
    test_loader = custom_data_loader.benchmarkLoader(args)
    model = custom_model.buildModel(args)
    recorder = recorders.Records(args.log_dir)
    test_utils.test(args, 'test', test_loader, model, log, 1, recorder)
    log.plotCurves(recorder, 'test')