diff --git a/pipelines/local_configs/__base__/datasets/easyportrait_1024x1024.py b/pipelines/local_configs/__base__/datasets/easyportrait_1024x1024.py index eca3c19..0f641b1 100644 --- a/pipelines/local_configs/__base__/datasets/easyportrait_1024x1024.py +++ b/pipelines/local_configs/__base__/datasets/easyportrait_1024x1024.py @@ -1,59 +1,88 @@ # dataset settings -dataset_type = 'EasyPortraitDataset' -data_root = 'path/to/data/EasyPortrait' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) +dataset_type = 'EasyPortraitFPDataset' +data_root = 'data/easyportrait/' +crop_size = (1024, 1024) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), - dict(type='Pad', size=(1920, 1920), pad_val=0, seg_pad_val=255), - dict(type='Resize', img_scale=(1024, 1024)), + dict( + type='RandomResize', + scale=(1024, 1024), + ratio_range=(1.0, 1.0), # keep the aspect ratio + keep_ratio=True), + + dict(type='RandomCrop', crop_size=crop_size), # We don't use RandomFlip, but need it in the code to fix error: https://github.com/open-mmlab/mmsegmentation/issues/231 - dict(type='RandomFlip', prob=0.0), + dict(type='RandomFlip', prob=0.0), dict(type='PhotoMetricDistortion', brightness_delta=16, contrast_range=(0.5, 1.0), saturation_range=(0.5, 1.0), - hue_delta=9), - dict(type='Normalize', **img_norm_cfg), - dict(type='DefaultFormatBundle'), - dict(type='Collect', keys=['img', 'gt_semantic_seg']), + hue_delta=9), + dict(type='PackSegInputs') ] - test_pipeline = [ dict(type='LoadImageFromFile'), + dict(type='Resize', scale=(1024, 1024), keep_ratio=True), + 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='MultiScaleFlipAug', - img_scale=(1024, 1024), - flip=False, + type='TestTimeAug', transforms=[ - dict(type='Resize', keep_ratio=True), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='Collect', keys=['img']), + [ + 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')] ]) ] -data = dict( - samples_per_gpu=4, - workers_per_gpu=4, - train=dict( +train_dataloader = dict( + # Increased batch size, maximmum on the + batch_size=4, + num_workers=4, + persistent_workers=True, + sampler=dict(type='InfiniteSampler', shuffle=True), + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/train', - ann_dir='annotations/train', - pipeline=train_pipeline), - val=dict( + data_prefix=dict( + img_path='images/train', seg_map_path='annotations/train'), + pipeline=train_pipeline)) + +val_dataloader = dict( + batch_size=1, + num_workers=4, + persistent_workers=True, + sampler=dict(type='DefaultSampler', shuffle=False), # Do not shuffle during validation + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/val', - ann_dir='annotations/val', - pipeline=test_pipeline), - test=dict( + data_prefix=dict( + img_path='images/val', seg_map_path='annotations/val'), + pipeline=test_pipeline)) +test_dataloader = dict( + batch_size=1, + num_workers=4, + persistent_workers=True, + sampler=dict(type='DefaultSampler', shuffle=False), # Do not shuffle during validation + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/test', - ann_dir='annotations/test', - pipeline=test_pipeline)) \ No newline at end of file + data_prefix=dict( + img_path='images/test', seg_map_path='annotations/test'), + pipeline=test_pipeline)) + +val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) # metric to measure the accuracy (mean IoU) +test_evaluator = val_evaluator \ No newline at end of file diff --git a/pipelines/local_configs/__base__/datasets/easyportrait_384x384.py b/pipelines/local_configs/__base__/datasets/easyportrait_384x384.py index f1aef5a..9867765 100644 --- a/pipelines/local_configs/__base__/datasets/easyportrait_384x384.py +++ b/pipelines/local_configs/__base__/datasets/easyportrait_384x384.py @@ -1,59 +1,88 @@ # dataset settings -dataset_type = 'EasyPortraitDataset' -data_root = 'path/to/data/EasyPortrait' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) +dataset_type = 'EasyPortraitFPDataset' +data_root = 'data/easyportrait/' +crop_size = (384, 384) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), - dict(type='Pad', size=(1920, 1920), pad_val=0, seg_pad_val=255), - dict(type='Resize', img_scale=(384, 384)), + dict( + type='RandomResize', + scale=(384, 384), + ratio_range=(1.0, 1.0), # keep the aspect ratio + keep_ratio=True), + + dict(type='RandomCrop', crop_size=crop_size), # We don't use RandomFlip, but need it in the code to fix error: https://github.com/open-mmlab/mmsegmentation/issues/231 dict(type='RandomFlip', prob=0.0), dict(type='PhotoMetricDistortion', brightness_delta=16, contrast_range=(0.5, 1.0), saturation_range=(0.5, 1.0), - hue_delta=9), - dict(type='Normalize', **img_norm_cfg), - dict(type='DefaultFormatBundle'), - dict(type='Collect', keys=['img', 'gt_semantic_seg']), + hue_delta=9), + dict(type='PackSegInputs') ] - test_pipeline = [ dict(type='LoadImageFromFile'), + dict(type='Resize', scale=(384, 384), keep_ratio=True), + 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='MultiScaleFlipAug', - img_scale=(384, 384), - flip=False, + type='TestTimeAug', transforms=[ - dict(type='Resize', keep_ratio=True), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='Collect', keys=['img']), + [ + 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')] ]) ] -data = dict( - samples_per_gpu=4, - workers_per_gpu=4, - train=dict( +train_dataloader = dict( + # Increased batch size, maximmum on the + batch_size=4, + num_workers=4, + persistent_workers=True, + sampler=dict(type='InfiniteSampler', shuffle=True), + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/train', - ann_dir='annotations/train', - pipeline=train_pipeline), - val=dict( + data_prefix=dict( + img_path='images/train', seg_map_path='annotations/train'), + pipeline=train_pipeline)) + +val_dataloader = dict( + batch_size=1, + num_workers=4, + persistent_workers=True, + sampler=dict(type='DefaultSampler', shuffle=False), # Do not shuffle during validation + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/val', - ann_dir='annotations/val', - pipeline=test_pipeline), - test=dict( + data_prefix=dict( + img_path='images/val', seg_map_path='annotations/val'), + pipeline=test_pipeline)) +test_dataloader = dict( + batch_size=1, + num_workers=4, + persistent_workers=True, + sampler=dict(type='DefaultSampler', shuffle=False), # Do not shuffle during validation + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/test', - ann_dir='annotations/test', - pipeline=test_pipeline)) \ No newline at end of file + data_prefix=dict( + img_path='images/test', seg_map_path='annotations/test'), + pipeline=test_pipeline)) + +val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) # metric to measure the accuracy (mean IoU) +test_evaluator = val_evaluator \ No newline at end of file diff --git a/pipelines/local_configs/__base__/datasets/easyportrait_512x512.py b/pipelines/local_configs/__base__/datasets/easyportrait_512x512.py index 09cca6d..29d796a 100644 --- a/pipelines/local_configs/__base__/datasets/easyportrait_512x512.py +++ b/pipelines/local_configs/__base__/datasets/easyportrait_512x512.py @@ -1,59 +1,88 @@ # dataset settings -dataset_type = 'EasyPortraitDataset' -data_root = 'path/to/data/EasyPortrait' -img_norm_cfg = dict( - mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True) +dataset_type = 'EasyPortraitFPDataset' +data_root = 'data/easyportrait/' +crop_size = (512, 512) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), - dict(type='Pad', size=(1920, 1920), pad_val=0, seg_pad_val=255), - dict(type='Resize', img_scale=(512, 512)), + dict( + type='RandomResize', + scale=(512, 512), + ratio_range=(1.0, 1.0), # keep the aspect ratio + keep_ratio=True), + + dict(type='RandomCrop', crop_size=crop_size), # We don't use RandomFlip, but need it in the code to fix error: https://github.com/open-mmlab/mmsegmentation/issues/231 dict(type='RandomFlip', prob=0.0), dict(type='PhotoMetricDistortion', brightness_delta=16, contrast_range=(0.5, 1.0), saturation_range=(0.5, 1.0), - hue_delta=9), - dict(type='Normalize', **img_norm_cfg), - dict(type='DefaultFormatBundle'), - dict(type='Collect', keys=['img', 'gt_semantic_seg']), + hue_delta=9), + dict(type='PackSegInputs') ] - test_pipeline = [ dict(type='LoadImageFromFile'), + dict(type='Resize', scale=(512, 512), keep_ratio=True), + 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='MultiScaleFlipAug', - img_scale=(512, 512), - flip=False, + type='TestTimeAug', transforms=[ - dict(type='Resize', keep_ratio=True), - dict(type='Normalize', **img_norm_cfg), - dict(type='ImageToTensor', keys=['img']), - dict(type='Collect', keys=['img']), + [ + 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')] ]) ] -data = dict( - samples_per_gpu=4, - workers_per_gpu=4, - train=dict( +train_dataloader = dict( + # Increased batch size, maximmum on the + batch_size=4, + num_workers=4, + persistent_workers=True, + sampler=dict(type='InfiniteSampler', shuffle=True), + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/train', - ann_dir='annotations/train', - pipeline=train_pipeline), - val=dict( + data_prefix=dict( + img_path='images/train', seg_map_path='annotations/train'), + pipeline=train_pipeline)) + +val_dataloader = dict( + batch_size=1, + num_workers=4, + persistent_workers=True, + sampler=dict(type='DefaultSampler', shuffle=False), # Do not shuffle during validation + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/val', - ann_dir='annotations/val', - pipeline=test_pipeline), - test=dict( + data_prefix=dict( + img_path='images/val', seg_map_path='annotations/val'), + pipeline=test_pipeline)) +test_dataloader = dict( + batch_size=1, + num_workers=4, + persistent_workers=True, + sampler=dict(type='DefaultSampler', shuffle=False), # Do not shuffle during validation + dataset=dict( type=dataset_type, data_root=data_root, - img_dir='images/test', - ann_dir='annotations/test', - pipeline=test_pipeline)) \ No newline at end of file + data_prefix=dict( + img_path='images/test', seg_map_path='annotations/test'), + pipeline=test_pipeline)) + +val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) # metric to measure the accuracy (mean IoU) +test_evaluator = val_evaluator \ No newline at end of file diff --git a/pipelines/mmseg/datasets/easy_portrait.py b/pipelines/mmseg/datasets/easy_portrait.py index e65f176..1a281d1 100644 --- a/pipelines/mmseg/datasets/easy_portrait.py +++ b/pipelines/mmseg/datasets/easy_portrait.py @@ -1,15 +1,9 @@ -import os.path as osp - -import mmcv -import numpy as np -from PIL import Image - -from .builder import DATASETS -from .custom import CustomDataset +from mmseg.registry import DATASETS +from .basesegdataset import BaseSegDataset @DATASETS.register_module() -class EasyPortraitDataset(CustomDataset): +class EasyPortraitDataset(BaseSegDataset): """EasyPortrait dataset. In segmentation map annotation for EasyPortrait, 0 stands for background, @@ -17,14 +11,14 @@ class EasyPortraitDataset(CustomDataset): The ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to '.png'. """ - - CLASSES = ('background', 'person', 'skin', + METAINFO = dict( + classes = ('background', 'person', 'skin', 'left brow', 'right brow', 'left eye', - 'right eye', 'lips', 'teeth') + 'right eye', 'lips', 'teeth'), - PALETTE = [[0, 0, 0], [223, 87, 188], [160, 221, 255], + palette=[[0, 0, 0], [223, 87, 188], [160, 221, 255], [130, 106, 237], [200, 121, 255], [255, 183, 255], - [0, 144, 193], [113, 137, 255], [230, 232, 230]] + [0, 144, 193], [113, 137, 255], [230, 232, 230]]) def __init__(self, **kwargs): super(EasyPortraitDataset, self).__init__( @@ -32,4 +26,4 @@ def __init__(self, **kwargs): seg_map_suffix='.png', reduce_zero_label=False, **kwargs) - assert self.file_client.exists(self.img_dir) \ No newline at end of file + #assert self.file_client.exists(self.img_dir) \ No newline at end of file diff --git a/pipelines/mmseg/datasets/easy_portrait_face_parsing.py b/pipelines/mmseg/datasets/easy_portrait_face_parsing.py index 4249940..577b129 100644 --- a/pipelines/mmseg/datasets/easy_portrait_face_parsing.py +++ b/pipelines/mmseg/datasets/easy_portrait_face_parsing.py @@ -1,15 +1,9 @@ -import os.path as osp - -import mmcv -import numpy as np -from PIL import Image - -from .builder import DATASETS -from .custom import CustomDataset +from mmseg.registry import DATASETS +from .basesegdataset import BaseSegDataset @DATASETS.register_module() -class EasyPortraitFPDataset(CustomDataset): +class EasyPortraitFPDataset(BaseSegDataset): """EasyPortraitFPDataset dataset. In segmentation map annotation for EasyPortrait, 0 stands for background, @@ -18,13 +12,15 @@ class EasyPortraitFPDataset(CustomDataset): '.png'. """ - CLASSES = ('background', 'skin', - 'left brow', 'right brow', 'left eye', - 'right eye', 'lips', 'teeth') + METAINFO = dict( - PALETTE = [[0, 0, 0], [160, 221, 255], - [130, 106, 237], [200, 121, 255], [255, 183, 255], - [0, 144, 193], [113, 137, 255], [230, 232, 230]] + classes = ('background', 'skin', + 'left brow', 'right brow', 'left eye', + 'right eye', 'lips', 'teeth'), + + palette = [[0, 0, 0], [160, 221, 255], + [130, 106, 237], [200, 121, 255], [255, 183, 255], + [0, 144, 193], [113, 137, 255], [230, 232, 230]]) def __init__(self, **kwargs): super(EasyPortraitFPDataset, self).__init__( @@ -32,10 +28,10 @@ def __init__(self, **kwargs): seg_map_suffix='.png', reduce_zero_label=False, **kwargs) - assert self.file_client.exists(self.img_dir) + #assert self.file_client.exists(self.img_dir) @DATASETS.register_module() -class EasyPortraitFPDatasetCross(CustomDataset): +class EasyPortraitFPDatasetCross(BaseSegDataset): """EasyPortraitFPDatasetCross dataset. In segmentation map annotation for EasyPortrait, 0 stands for background, @@ -43,16 +39,17 @@ class EasyPortraitFPDatasetCross(CustomDataset): The ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to '.png'. """ - - CLASSES = ('background', 'left brow', 'right brow', 'left eye', 'right eye', 'lips') - PALETTE = [[0, 0, 0], [160, 221, 255], - [130, 106, 237], [200, 121, 255], [255, 183, 255], - [0, 144, 193]] + METAINFO = dict( + classes = ('background', 'left brow', 'right brow', 'left eye', 'right eye', 'lips'), + palette = [[0, 0, 0], [160, 221, 255], + [130, 106, 237], [200, 121, 255], [255, 183, 255], + [0, 144, 193]]) + def __init__(self, **kwargs): super(EasyPortraitFPDatasetCross, self).__init__( img_suffix='.jpg', seg_map_suffix='.png', reduce_zero_label=False, **kwargs) - assert self.file_client.exists(self.img_dir) \ No newline at end of file + #assert self.file_client.exists(self.img_dir) \ No newline at end of file diff --git a/pipelines/mmseg/datasets/easy_portrait_portrait_segmentation.py b/pipelines/mmseg/datasets/easy_portrait_portrait_segmentation.py index cb36502..ae47186 100644 --- a/pipelines/mmseg/datasets/easy_portrait_portrait_segmentation.py +++ b/pipelines/mmseg/datasets/easy_portrait_portrait_segmentation.py @@ -1,15 +1,8 @@ -import os.path as osp - -import mmcv -import numpy as np -from PIL import Image - -from .builder import DATASETS -from .custom import CustomDataset - +from mmseg.registry import DATASETS +from .basesegdataset import BaseSegDataset @DATASETS.register_module() -class EasyPortraitPSDataset(CustomDataset): +class EasyPortraitPSDataset(BaseSegDataset): """EasyPortrait dataset. In segmentation map annotation for EasyPortrait, 0 stands for background, @@ -18,9 +11,10 @@ class EasyPortraitPSDataset(CustomDataset): '.png'. """ - CLASSES = ('background', 'person') + METAINFO = dict( + classes = ('background', 'person'), - PALETTE = [[0, 0, 0], [160, 221, 255]] + palette = [[0, 0, 0], [160, 221, 255]]) def __init__(self, **kwargs): super(EasyPortraitPSDataset, self).__init__( @@ -28,4 +22,4 @@ def __init__(self, **kwargs): seg_map_suffix='.png', reduce_zero_label=False, **kwargs) - assert self.file_client.exists(self.img_dir) \ No newline at end of file + #assert self.file_client.exists(self.img_dir) \ No newline at end of file