Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Tonyzhang2000/dev
Group Internal Merge ACDC Dataset.
- Loading branch information
Showing
9 changed files
with
230 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# dataset settings | ||
dataset_type = 'ACDCDataset' | ||
data_root = 'data/acdc/' | ||
crop_size = (512, 1024) | ||
train_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='LoadAnnotations'), | ||
dict( | ||
type='RandomResize', | ||
scale=(2048, 1024), | ||
ratio_range=(0.5, 2.0), | ||
keep_ratio=True), | ||
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75), | ||
dict(type='RandomFlip', prob=0.5), | ||
dict(type='PhotoMetricDistortion'), | ||
dict(type='PackSegInputs') | ||
] | ||
test_pipeline = [ | ||
dict(type='LoadImageFromFile'), | ||
dict(type='Resize', scale=(2048, 1024), keep_ratio=True), | ||
# add loading annotation after ``Resize`` because ground truth | ||
# does not need to do resize data transform | ||
dict(type='LoadAnnotations'), | ||
dict(type='PackSegInputs') | ||
] | ||
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] | ||
tta_pipeline = [ | ||
dict(type='LoadImageFromFile', backend_args=None), | ||
dict( | ||
type='TestTimeAug', | ||
transforms=[ | ||
[ | ||
dict(type='Resize', scale_factor=r, keep_ratio=True) | ||
for r in img_ratios | ||
], | ||
[ | ||
dict(type='RandomFlip', prob=0., direction='horizontal'), | ||
dict(type='RandomFlip', prob=1., direction='horizontal') | ||
], [dict(type='LoadAnnotations')], [dict(type='PackSegInputs')] | ||
]) | ||
] | ||
train_dataloader = dict( | ||
batch_size=2, | ||
num_workers=2, | ||
persistent_workers=True, | ||
sampler=dict(type='InfiniteSampler', shuffle=True), | ||
dataset=dict( | ||
type=dataset_type, | ||
data_root=data_root, | ||
data_prefix=dict(img_path='rgb_anno/train', seg_map_path='gt/train'), | ||
pipeline=train_pipeline)) | ||
val_dataloader = dict( | ||
batch_size=1, | ||
num_workers=4, | ||
persistent_workers=True, | ||
sampler=dict(type='DefaultSampler', shuffle=False), | ||
dataset=dict( | ||
type=dataset_type, | ||
data_root=data_root, | ||
data_prefix=dict(img_path='rgb_anno/test', seg_map_path='gt/test'), | ||
pipeline=test_pipeline)) | ||
test_dataloader = val_dataloader | ||
|
||
val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) | ||
test_evaluator = val_evaluator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
_base_ = [ | ||
'../_base_/models/pspnet_r50-d8.py', '../_base_/datasets/acdc.py', | ||
'../_base_/default_runtime.py', '../_base_/schedules/schedule_40k.py' | ||
] | ||
crop_size = (512, 1024) | ||
data_preprocessor = dict(size=crop_size) | ||
model = dict(data_preprocessor=data_preprocessor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from mmseg.registry import DATASETS | ||
from .cityscapes import CityscapesDataset | ||
|
||
|
||
@DATASETS.register_module() | ||
class ACDCDataset(CityscapesDataset): | ||
"""ACDCDataset dataset.""" | ||
|
||
def __init__(self, | ||
img_suffix='_rgb_anon.png', | ||
seg_map_suffix='_gt_labelTrainIds.png', | ||
**kwargs) -> None: | ||
super().__init__( | ||
img_suffix=img_suffix, seg_map_suffix=seg_map_suffix, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
import argparse | ||
import os | ||
import os.path as osp | ||
import shutil | ||
|
||
from mmengine.utils import mkdir_or_exist | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description='Convert ACDC dataset to mmsegmentation format') | ||
parser.add_argument('raw_data', help='the path of raw data') | ||
parser.add_argument( | ||
'-o', '--out_dir', help='output path', default='./data/acdc') | ||
parser.add_argument( | ||
'--split', | ||
choices=['fog', 'night', 'rain', 'snow', 'all'], | ||
default='night') | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
|
||
try: | ||
shutil.rmtree(args.out_dir) | ||
print('Directory removed successfully') | ||
except OSError as e: | ||
print(f'Error: {e.strerror}') | ||
|
||
print('Making directories...') | ||
mkdir_or_exist(args.out_dir) | ||
for subdir in ['gt/test', 'rgb_anno/test', 'gt/train', 'rgb_anno/train']: | ||
mkdir_or_exist(osp.join(args.out_dir, subdir)) | ||
|
||
print('Moving images and annotations...') | ||
|
||
if args.split == 'all': | ||
anno_str_test = '/val/' | ||
gt_str_test = '/val/' | ||
anno_str_train = '/train/' | ||
gt_str_train = '/train/' | ||
else: | ||
anno_str_test = f'rgb_anon/{args.split}/val/' | ||
gt_str_test = f'gt/{args.split}/val/' | ||
anno_str_train = f'rgb_anon/{args.split}/train/' | ||
gt_str_train = f'gt/{args.split}/train/' | ||
|
||
for dirpath, _, filenames in os.walk(args.raw_data): | ||
for filename in filenames: | ||
full_path = os.path.join(dirpath, filename) | ||
|
||
if anno_str_test in full_path: | ||
if full_path.endswith('_rgb_anon.png'): | ||
new_path = os.path.join(args.out_dir, 'rgb_anno/test', | ||
filename) | ||
shutil.copy(full_path, new_path) | ||
elif gt_str_test in full_path: | ||
if full_path.endswith('_gt_labelTrainIds.png'): | ||
new_path = os.path.join(args.out_dir, 'gt/test', filename) | ||
shutil.copy(full_path, new_path) | ||
if anno_str_train in full_path: | ||
if full_path.endswith('_rgb_anon.png'): | ||
new_path = os.path.join(args.out_dir, 'rgb_anno/train', | ||
filename) | ||
shutil.copy(full_path, new_path) | ||
elif gt_str_train in full_path: | ||
if full_path.endswith('_gt_labelTrainIds.png'): | ||
new_path = os.path.join(args.out_dir, 'gt/train', filename) | ||
shutil.copy(full_path, new_path) | ||
|
||
print('Done!') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |