def test_concat_ade(separate_eval): test_dataset = ADE20KDataset( pipeline=[], img_dir=osp.join(osp.dirname(__file__), '../data/pseudo_dataset/imgs')) assert len(test_dataset) == 5 concat_dataset = ConcatDataset([test_dataset, test_dataset], separate_eval=separate_eval) assert len(concat_dataset) == 10 # Test format_results pseudo_results = [] for _ in range(len(concat_dataset)): h, w = (2, 2) pseudo_results.append(np.random.randint(low=0, high=7, size=(h, w))) # test format per image file_paths = [] for i in range(len(pseudo_results)): file_paths.extend( concat_dataset.format_results([pseudo_results[i]], '.format_ade', indices=[i])) assert len(file_paths) == len(concat_dataset) temp = np.array(Image.open(file_paths[0])) assert np.allclose(temp, pseudo_results[0] + 1) shutil.rmtree('.format_ade') # test default argument file_paths = concat_dataset.format_results(pseudo_results, '.format_ade') assert len(file_paths) == len(concat_dataset) temp = np.array(Image.open(file_paths[0])) assert np.allclose(temp, pseudo_results[0] + 1) shutil.rmtree('.format_ade')
def ade20k_datasets(FLAGS): img_norm_cfg = dict(mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) crop_size = (512, 512) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', reduce_zero_label=True), dict(type='Resize', img_scale=(2048, 512), ratio_range=(0.5, 2.0)), dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), dict(type='RandomFlip', flip_ratio=0.5), dict(type='PhotoMetricDistortion'), dict(type='Normalize', **img_norm_cfg), dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img', 'gt_semantic_seg']), ] test_pipeline = [ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=(2048, 512), # img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75], flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict(type='Normalize', **img_norm_cfg), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']), ]) ] train_pipeline = Compose(train_pipeline) val_pipeline = Compose(test_pipeline) train_set = ADE20KDataset(data_root=FLAGS.data_root, img_dir='images/training', ann_dir='annotations/training', pipeline=train_pipeline) val_set = ADE20KDataset(data_root=FLAGS.data_root, img_dir='images/validation', ann_dir='annotations/validation', pipeline=val_pipeline, test_mode=True) return train_set, val_set, None
def test_ade(): test_dataset = ADE20KDataset( pipeline=[], img_dir=osp.join(osp.dirname(__file__), '../data/pseudo_dataset/imgs')) assert len(test_dataset) == 5 # Test format_results pseudo_results = [] for _ in range(len(test_dataset)): h, w = (2, 2) pseudo_results.append(np.random.randint(low=0, high=7, size=(h, w))) file_paths = test_dataset.format_results(pseudo_results, '.format_ade') assert len(file_paths) == len(test_dataset) temp = np.array(Image.open(file_paths[0])) assert np.allclose(temp, pseudo_results[0] + 1) shutil.rmtree('.format_ade')
def test_concat_cityscapes(separate_eval): cityscape_dataset = CityscapesDataset( pipeline=[], img_dir=osp.join(osp.dirname(__file__), '../data/pseudo_cityscapes_dataset/leftImg8bit'), ann_dir=osp.join(osp.dirname(__file__), '../data/pseudo_cityscapes_dataset/gtFine')) assert len(cityscape_dataset) == 1 with pytest.raises(NotImplementedError): _ = ConcatDataset([cityscape_dataset, cityscape_dataset], separate_eval=separate_eval) ade_dataset = ADE20KDataset(pipeline=[], img_dir=osp.join( osp.dirname(__file__), '../data/pseudo_dataset/imgs')) assert len(ade_dataset) == 5 with pytest.raises(NotImplementedError): _ = ConcatDataset([cityscape_dataset, ade_dataset], separate_eval=separate_eval)