Exemple #1
0
def main():
    # parse options, set distributed setting, set ramdom seed
    opt = parse_options(is_train=False)

    torch.backends.cudnn.benchmark = True
    # torch.backends.cudnn.deterministic = True

    # mkdir and initialize loggers
    make_exp_dirs(opt)
    log_file = osp.join(opt['path']['log'],
                        f"test_{opt['name']}_{get_time_str()}.log")
    logger = get_root_logger(
        logger_name='basicsr', log_level=logging.INFO, log_file=log_file)
    logger.info(get_env_info())
    logger.info(dict2str(opt))

    # create test dataset and dataloader
    test_loaders = []
    for phase, dataset_opt in sorted(opt['datasets'].items()):
        test_set = create_dataset(dataset_opt)
        test_loader = create_dataloader(
            test_set,
            dataset_opt,
            num_gpu=opt['num_gpu'],
            dist=opt['dist'],
            sampler=None,
            seed=opt['manual_seed'])
        logger.info(
            f"Number of test images in {dataset_opt['name']}: {len(test_set)}")
        test_loaders.append(test_loader)

    # create model
    model = create_model(opt)

    for test_loader in test_loaders:
        test_set_name = test_loader.dataset.opt['name']
        logger.info(f'Testing {test_set_name}...')
        rgb2bgr = opt['val'].get('rgb2bgr', True)
        # wheather use uint8 image to compute metrics
        use_image = opt['val'].get('use_image', True)
        model.validation(
            test_loader,
            current_iter=opt['name'],
            tb_logger=None,
            save_img=opt['val']['save_img'],
            rgb2bgr=rgb2bgr, use_image=use_image)
Exemple #2
0
def parse_args(train=True):
    parser = argparse.ArgumentParser(description="")
    if train:
        parser.add_argument('--opt', default='options/train/SRResNet_SRGAN/train_MSRResNet_x4.yml')
        # parser.add_argument('--opt', default='options/train/CARN/train_CARN_x4.yml')
        # parser.add_argument('--opt', default='options/train/CARN/train_CARNA_x4.yml')
        # parser.add_argument('--opt', default='options/train/EDSR/train_EDSR_Mx4.yml')
        # parser.add_argument('--opt', default='options/train/SRResNet_SRGAN/train_MSRResNetD_x4.yml')
        # parser.add_argument('--opt', default='options/train/RFDN/train_RFDN_x4.yml')
        # parser.add_argument('--opt', default='options/train/IMDN/train_IMDN_x4.yml')
    else:
        # parser.add_argument('--opt', default='options/test/SRResNet_SRGAN/test_MSRResNet_x4.yml')
        # parser.add_argument('--opt', default='options/test/SRResNet_SRGAN/test_MSRResNet_x4_woGT.yml')
        # parser.add_argument('--opt', default='options/test/CARN/test_CARN_x4.yml')
        parser.add_argument('--opt', default='options/test/CARN/test_CARN_x4_woGT.yml')

    parser.add_argument('--launcher', default='none')
    parser.add_argument('--local_rank', type=int, default=0)
    return parser

if __name__ == '__main__':
    is_train = True
    parser = parse_args(train=is_train)
    args = parser.parse_args()
    if is_train:
        opt = train.parse_options(args=args)
        train.main(opt)
    else:
        test_opt = test.parse_options(is_train=is_train, args=args)
        test.main(test_opt)