Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Albumentations default key mapping mismatch #3195

Merged
merged 3 commits into from
Jul 14, 2023
Merged

[Fix] Albumentations default key mapping mismatch #3195

merged 3 commits into from
Jul 14, 2023

Conversation

Alias-z
Copy link
Contributor

@Alias-z Alias-z commented Jul 13, 2023

Modification

Fix Albumentations default key mapping mismatch as mentioned in issue # 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

Example viz_dataset after the issue fixing
A thaliana Lucia 07 2022 col-0 30m-1h after Infection 22162057 object id 0

fix Albumentations default key mapping mismatch
@CLAassistant
Copy link

CLAassistant commented Jul 13, 2023

CLA assistant check
All committers have signed the CLA.

@xiexinch xiexinch changed the base branch from main to dev-1.x July 14, 2023 04:06
@xiexinch xiexinch merged commit 20fa129 into open-mmlab:dev-1.x Jul 14, 2023
8 of 10 checks passed
@OpenMMLab-Assistant-004

Hi @Alias-z,

We'd like to express our appreciation for your valuable contributions to the mmsegmentation. Your efforts have significantly aided in enhancing the project's quality.
It is our pleasure to invite you to join our community thorugh Discord_Special Interest Group (SIG) channel. This is a great place to share your experiences, discuss ideas, and connect with other like-minded people. To become a part of the SIG channel, send a message to the moderator, OpenMMLab, briefly introduce yourself and mention your open-source contributions in the #introductions channel. Our team will gladly facilitate your entry. We eagerly await your presence. Please follow this link to join us: ​https://discord.gg/UjgXkPWNqA.

If you're on WeChat, we'd also love for you to join our community there. Just add our assistant using the WeChat ID: openmmlabwx. When sending the friend request, remember to include the remark "mmsig + Github ID".

Thanks again for your awesome contribution, and we're excited to have you as part of our community!

nahidnazifi87 pushed a commit to nahidnazifi87/mmsegmentation_playground that referenced this pull request Apr 5, 2024
## 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 <xiexinch@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants