Exemple #1
0
    from utils.parse_args import parse_args
    from utils.print_easydict import print_easydict

    args = parse_args('Deep learning of graph matching evaluation code.')

    import importlib
    mod = importlib.import_module(cfg.MODULE)
    Net = mod.Net

    torch.manual_seed(cfg.RANDOM_SEED)

    image_dataset = GMDataset(cfg.DATASET_FULL_NAME,
                              sets='test',
                              length=cfg.EVAL.SAMPLES,
                              obj_resize=cfg.PAIR.RESCALE)
    dataloader = get_dataloader(image_dataset)

    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    model = Net()
    model = model.cuda()
    model = DataParallel(model, device_ids=range(torch.cuda.device_count()))

    if not Path(cfg.OUTPUT_PATH).exists():
        Path(cfg.OUTPUT_PATH).mkdir(parents=True)
    now_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
    with DupStdoutFileManager(
            str(Path(cfg.OUTPUT_PATH) /
                ('eval_log_' + now_time + '.log'))) as _:
        print_easydict(cfg)
        classes = dataloader.dataset.classes
Exemple #2
0
                              port=cfg.VISDOM.PORT)
        Visdomins.viz.close()
    else:
        Visdomins = None

    torch.manual_seed(cfg.RANDOM_SEED)

    pc_dataset = get_datasets(partition='test',
                              num_points=cfg.DATASET.POINT_NUM,
                              unseen=cfg.DATASET.UNSEEN,
                              noise_type=cfg.DATASET.NOISE_TYPE,
                              rot_mag=cfg.DATASET.ROT_MAG,
                              trans_mag=cfg.DATASET.TRANS_MAG,
                              partial_p_keep=cfg.DATASET.PARTIAL_P_KEEP)

    dataloader = get_dataloader(pc_dataset)

    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    model = Net()
    model = model.to(device)
    model = DataParallel(model, device_ids=cfg.GPUS)

    if not Path(cfg.OUTPUT_PATH).exists():
        Path(cfg.OUTPUT_PATH).mkdir(parents=True)
    now_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
    with DupStdoutFileManager(
            str(Path(cfg.OUTPUT_PATH) /
                ('eval_log_' + now_time + '.log'))) as _:
        print_easydict(cfg)
        metrics = eval_model(
    Net = mod.Net

    torch.manual_seed(cfg.RANDOM_SEED)

    dataset_len = {'train': cfg.TRAIN.EPOCH_ITERS * cfg.BATCH_SIZE, 'test': cfg.EVAL.SAMPLES}
    data_fn = GMDataset
    if cfg.MODULE == 'GL.model':
        data_fn = GLDataset
    image_dataset = {
        x: data_fn(cfg.DATASET_FULL_NAME,
                     sets=x,
                     length=dataset_len[x],
                     cls=cfg.TRAIN.CLASS if x == 'train' else None,
                     obj_resize=cfg.PAIR.RESCALE)
        for x in ('train', 'test')}
    dataloader = {x: get_dataloader(image_dataset[x], fix_seed=(x == 'test'))
        for x in ('train', 'test')}

    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    model = Net()
    model = model.cuda()

    if cfg.TRAIN.LOSS_FUNC == 'offset':
        criterion = RobustLoss(norm=cfg.TRAIN.RLOSS_NORM)
    elif cfg.TRAIN.LOSS_FUNC == 'perm':
        criterion = CrossEntropyLoss()
    else:
        raise ValueError('Unknown loss function {}'.format(cfg.TRAIN.LOSS_FUNC))

    optimizer = optim.SGD(model.parameters(), lr=cfg.TRAIN.LR, momentum=cfg.TRAIN.MOMENTUM, nesterov=True)
Exemple #4
0
                        crossval=(x == 'train'),
                        train_part=(x == 'train'))
        for x in ('train', 'test')
    }
    pc_dataset['val'] = get_datasets(partition='train',
                                     num_points=cfg.DATASET.POINT_NUM,
                                     unseen=cfg.DATASET.UNSEEN,
                                     noise_type=cfg.DATASET.NOISE_TYPE,
                                     rot_mag=cfg.DATASET.ROT_MAG,
                                     trans_mag=cfg.DATASET.TRANS_MAG,
                                     partial_p_keep=cfg.DATASET.PARTIAL_P_KEEP,
                                     crossval=True,
                                     train_part=False)

    dataloader = {
        x: get_dataloader(pc_dataset[x], shuffle=(x == 'train'))
        for x in ('train', 'val', 'test')
    }

    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    model = Net()
    model = model.cuda()
    permLoss = PermLoss()

    if cfg.TRAIN.OPTIM == 'SGD':
        optimizer = optim.SGD(model.parameters(),
                              lr=cfg.TRAIN.LR,
                              momentum=cfg.TRAIN.MOMENTUM,
                              nesterov=True)
    else: