Skip to content

Commit 20fa129

Browse files
Alias-zxiexinch
andauthored
[Fix] Albumentations default key mapping mismatch (open-mmlab#3195)
## Modification Fix Albumentations default key mapping mismatch as mentioned in [issue # 3179](open-mmlab#3179) by changing `self.keymap_to_albu = { 'img': 'image', 'gt_masks': 'masks'}` to `self.keymap_to_albu = { 'img': 'image', 'gt_seg_map': 'mask'}` ## Use cases (Optional) Example albu config ``` crop_size = (512, 512) albu_train_transforms = [ dict( type='PadIfNeeded', min_height=crop_size[0]*2, min_width=crop_size[1]*2, border_mode=0, always_apply=True), dict(type='Flip', always_apply=True), dict(type='Rotate', limit=(-180, 180), interpolation=4, always_apply=True), dict(type='RandomScale', scale_limit=0.1, interpolation=4, always_apply=True), dict( type='ElasticTransform', alpha=20, sigma=15, interpolation=4, border_mode=0, mask_value=(0, 0, 0), approximate=True, same_dxdy=True, p=0.8), dict(type='ColorJitter', brightness=0.2, contrast=0.1, saturation=0.2, hue=0.2, always_apply=True), dict(type='AdvancedBlur', p=0.5), dict(type='CenterCrop', height=crop_size[0], width=crop_size[1], always_apply=True) ] ``` Example training pipeline without specifying `keymap` ``` train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', reduce_zero_label=False), dict( type='Albu', transforms=albu_train_transforms, ), dict(type='Resize', scale=crop_size, keep_ratio=False, interpolation='lanczos'), dict(type='PackSegInputs') ] ``` Example viz_dataset before the issue fixing ![A thaliana Lucia 07 2022 col-0 30m-1h after Infection 22162057 object id 0](https://github.com/open-mmlab/mmsegmentation/assets/66273343/5431472a-83fd-485f-aeb7-c65f27f1993d) Example viz_dataset after the issue fixing ![A thaliana Lucia 07 2022 col-0 30m-1h after Infection 22162057 object id 0](https://github.com/open-mmlab/mmsegmentation/assets/66273343/3d6d4937-41f0-4a18-ae47-35bc43d78843) --------- Co-authored-by: xiexinch <[email protected]>
1 parent 580f63e commit 20fa129

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

mmseg/datasets/transforms/transforms.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,10 +2206,7 @@ def __init__(self,
22062206
self.aug = Compose([self.albu_builder(t) for t in self.transforms])
22072207

22082208
if not keymap:
2209-
self.keymap_to_albu = {
2210-
'img': 'image',
2211-
'gt_masks': 'masks',
2212-
}
2209+
self.keymap_to_albu = {'img': 'image', 'gt_seg_map': 'mask'}
22132210
else:
22142211
self.keymap_to_albu = copy.deepcopy(keymap)
22152212
self.keymap_back = {v: k for k, v in self.keymap_to_albu.items()}

0 commit comments

Comments
 (0)