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

[Feature] Add MultiImageMixDataset #1105

Merged
merged 21 commits into from
Jan 11, 2022
Merged

[Feature] Add MultiImageMixDataset #1105

merged 21 commits into from
Jan 11, 2022

Conversation

lkm2835
Copy link
Contributor

@lkm2835 lkm2835 commented Dec 6, 2021

Modification

  • mmseg/datasets/builder.py: Add (if cfg['type'] == 'MultiImageMixDataset'])

  • mmseg/datasets/dataset_wrappers.py: Add class MultiImageMixDataset

  • tests/test_data/test_dataset.py: Add unittests

Use cases (Optional)

train_pipeline = [
    dict(type='Mosaic'),
    dict(type='Resize', img_scale=(1024, 512), keep_ratio=True),
    dict(type='RandomFlip', prob=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_semantic_seg']),
]

train_dataset = dict(
    type='MultiImageMixDataset',
    dataset=dict(
        classes=classes,
        palette=palette,
        type=dataset_type,
        reduce_zero_label=False, 
        img_dir=data_root + "images/train",
        ann_dir=data_root + "annotations/train",
        pipeline=[
            dict(type='LoadImageFromFile'),
            dict(type='LoadAnnotations'),
        ]  
    ),
    pipeline=train_pipeline
)

use case in mmdet


Original code: MultiImageMixDataset in mmdet
Related: Issue#1045, Pull Request#1093

@CLAassistant
Copy link

CLAassistant commented Dec 6, 2021

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Dec 6, 2021

Codecov Report

Merging #1105 (664d5da) into master (91cbe06) will increase coverage by 0.45%.
The diff coverage is 84.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1105      +/-   ##
==========================================
+ Coverage   89.57%   90.03%   +0.45%     
==========================================
  Files         120      125       +5     
  Lines        6717     7314     +597     
  Branches     1122     1219      +97     
==========================================
+ Hits         6017     6585     +568     
- Misses        496      524      +28     
- Partials      204      205       +1     
Flag Coverage Δ
unittests 90.03% <84.00%> (+0.45%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmseg/datasets/dataset_wrappers.py 92.12% <81.39%> (-5.55%) ⬇️
mmseg/datasets/__init__.py 100.00% <100.00%> (ø)
mmseg/datasets/builder.py 87.80% <100.00%> (+0.79%) ⬆️
mmseg/models/segmentors/base.py 57.85% <0.00%> (-4.10%) ⬇️
mmseg/models/backbones/swin.py 83.62% <0.00%> (-0.12%) ⬇️
mmseg/models/losses/__init__.py 100.00% <0.00%> (ø)
mmseg/models/losses/dice_loss.py 100.00% <0.00%> (ø)
mmseg/models/backbones/__init__.py 100.00% <0.00%> (ø)
mmseg/models/decode_heads/__init__.py 100.00% <0.00%> (ø)
mmseg/models/backbones/twins.py 99.40% <0.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91cbe06...664d5da. Read the comment docs.

@MengzhangLI
Copy link
Contributor

Hi, @lkm2835 thanks for your pr.

We would review it ASAP.

Best,

@Younghoon-Lee
Copy link
Contributor

Younghoon-Lee commented Dec 6, 2021

image

This is the sample image that is built by MultiImageMixDataset from our custom dataset.
As you can see, four images come together to form a single square.

@Junjun2016
Copy link
Collaborator

image

This is the sample image that is built by MultiImageMixDataset from our custom dataset. As you can see, four images come together to form a single square.

Could you please provide some results on your custom dataset?

@Younghoon-Lee
Copy link
Contributor

Could you please provide some results on your custom dataset?

Okay I see . We will do some tests with and without Mosaic. Please note that our custom dataset has a few noises in annotation.

@Junjun2016
Copy link
Collaborator

image
This is the sample image that is built by MultiImageMixDataset from our custom dataset. As you can see, four images come together to form a single square.

Could you please provide some results on your custom dataset?

It seems that you have set the opacity to 0, can set it to 0.5 to also show the label annotations.

@Junjun2016
Copy link
Collaborator

Please improve the unittests coverage.

@Junjun2016
Copy link
Collaborator

Can browse more images and label annotations to check the correctness of mosaic augmentation.

@Junjun2016
Copy link
Collaborator

Hi @RockeyCoss
Please review it and do some ablation studies.

@Younghoon-Lee
Copy link
Contributor

We made changes you requested. And I browsed about 100 images and annotations and they seemed all fine :)

@Junjun2016
Copy link
Collaborator

We made changes you requested. And I browsed about 100 images and annotations and they seemed all fine :)

Thanks for your hard work.
We could do some ablation studies together.
Looking forward to the result of your project.

@RockeyCoss
Copy link
Contributor

Thanks for your contribution. I will combine it with Mosaic data augmentation and do some experiments.

@lkm2835
Copy link
Contributor Author

lkm2835 commented Dec 11, 2021

mmseg/datasets/dataset_wrappers.py line 247 ~ 259

When it merged with Mosaic, it will be easy to improve the unittests coverage.

@Younghoon-Lee
Copy link
Contributor

Younghoon-Lee commented Dec 16, 2021

Thanks for your hard work. We could do some ablation studies together. Looking forward to the result of your project.

Sorry for taking so late. I brought some results below.
All results were applied of 512 img scale for Mosaic augmentation.

Mosaic_prob best best epoch last last epoch
0 0.5752 25 0.5685 50
0.5 0.5728 35 0.5696 50
1.0 0.5814 49 0.579 50

We have done different img scales test for Mosaic augmentation as well, but 512x512 showed best performance. (Mosaic prob =1.0)

img_scale best best epoch last last epoch
384 0.5297 38 0.5269 50
448 0.5632 49 0.5627 50
512 0.5814 49 0.579 50
576 0.5475 41 0.5405 50
640 0.544 46 0.5411 50

According to test results, Mosaic augmentation seems to show better performance on a few label images.

@Junjun2016
Copy link
Collaborator

Thanks for your hard work. We could do some ablation studies together. Looking forward to the result of your project.

Sorry for taking so late. I brought some results below. All results were applied of 512 img scale for Mosaic augmentation.

Mosaic_prob best best epoch last last epoch
0 0.5752 25 0.5685 50
0.5 0.5728 35 0.5696 50
1.0 0.5814 49 0.579 50
We have done different img scales test for Mosaic augmentation as well, but 512x512 showed best performance. (Mosaic prob =1.0)

img_scale best best epoch last last epoch
384 0.5297 38 0.5269 50
448 0.5632 49 0.5627 50
512 0.5814 49 0.579 50
576 0.5475 41 0.5405 50
640 0.544 46 0.5411 50
According to test results, Mosaic augmentation seems to show better performance on a few label images.

What's the best result on your custom dataset (SOTA)?

@Younghoon-Lee
Copy link
Contributor

What's the best result on your custom dataset (SOTA)?

The best result is 0.5814 ,which is 512x512 img scale for Mosaic(prob=1) augmentation.

Here is config script for more detail.

train_pipeline = [
    dict(type='RandomMosaic', prob=1, img_scale=(512,512)),
    dict(type='RandomCrop', crop_size=(512, 512)),
    dict(type='RandomFlip', prob=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_semantic_seg']),
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(512,512),
        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']),
        ])
]

(segformer_mit-b0_512x512)

@Junjun2016
Copy link
Collaborator

What's the best result on your custom dataset (SOTA)?

The best result is 0.5814 ,which is 512x512 img scale for Mosaic(prob=1) augmentation.

Here is config script for more detail.

train_pipeline = [
    dict(type='RandomMosaic', prob=1, img_scale=(512,512)),
    dict(type='RandomCrop', crop_size=(512, 512)),
    dict(type='RandomFlip', prob=0.5),
    dict(type='Normalize', **img_norm_cfg),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img', 'gt_semantic_seg']),
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(512,512),
        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']),
        ])
]

(segformer_mit-b0_512x512)

I mean the best result you got before.
Can mosaic augmentation boost the best result?

@Younghoon-Lee
Copy link
Contributor

Younghoon-Lee commented Dec 16, 2021

I mean the best result you got before. Can mosaic augmentation boost the best result?

Oh I see.

Unfortunately, now we only have the best result which had been applied many tricks(due to competition),so it is hard to tell the best result of the model itself.

We will do test right away with same condition as before .

@Junjun2016
Copy link
Collaborator

I mean the best result you got before. Can mosaic augmentation boost the best result?

Oh I see.

Unfortunately, now we only have the best result which had been applied many tricks(due to competition),so it is hard to tell the best result of the model itself.

We will do test right away with same condition as before .

That may not be a good data augmentation strategy for segmentation.

@Younghoon-Lee
Copy link
Contributor

I mean the best result you got before. Can mosaic augmentation boost the best result?

Oh I see.
Unfortunately, now we only have the best result which had been applied many tricks(due to competition),so it is hard to tell the best result of the model itself.
We will do test right away with same condition as before .

That may not be a good data augmentation strategy for segmentation.

So we are just using SOTA model(without any tricks) we used and doing some augmentation tests only.

@Junjun2016
Copy link
Collaborator

I mean the best result you got before. Can mosaic augmentation boost the best result?

Oh I see.
Unfortunately, now we only have the best result which had been applied many tricks(due to competition),so it is hard to tell the best result of the model itself.
We will do test right away with same condition as before .

That may not be a good data augmentation strategy for segmentation.

So we are just using SOTA model(without any tricks) we used and doing some augmentation tests only.

Make sense.

@Younghoon-Lee
Copy link
Contributor

Younghoon-Lee commented Dec 20, 2021

Here's some results we have done.

exp_num method mIoU best best epoch mIoU last last epoch
1(SOTA) 512x512_epoch18 0.7627 11 0.7611 18
2 512x512_epoch18_mosaic_prob_0.2 0.7588 11 0.7571 18
3 512x512_epoch18_mosaic_prob_0.3 0.7577 14 0.7558 18
4 512x512_epoch18_mosaic_prob_0.5 0.7567 13 0.7566 18
5 512x512_epoch18_mosaic_prob_1.0 0.755 18 0.755 18

Actually, we did several more tests such as without crop, changing center ratio, img scale etc .
But It seemed that Mosaic couldn't boost our best result.

MeowZheng and others added 3 commits January 7, 2022 23:01
Co-authored-by: Miao Zheng <76149310+MeowZheng@users.noreply.github.com>
@Junjun2016 Junjun2016 merged commit 6c3e63e into open-mmlab:master Jan 11, 2022
bowenroom pushed a commit to bowenroom/mmsegmentation that referenced this pull request Feb 25, 2022
* Fix typo in usage example

* original MultiImageMixDataset code in mmdet

* Add MultiImageMixDataset unittests in test_dataset_wrapper

* fix lint error

* fix value name ann_file to ann_dir

* modify retrieve_data_cfg (#1)

* remove dynamic_scale & add palette

* modify retrieve_data_cfg method

* modify retrieve_data_cfg func

* fix error

* improve the unittests coverage

* fix unittests error

* Dataset (#2)

* add cfg-options

* Add unittest in test_build_dataset

* add blank line

* add blank line

* add a blank line

Co-authored-by: Miao Zheng <76149310+MeowZheng@users.noreply.github.com>

Co-authored-by: Younghoon-Lee <72462227+Younghoon-Lee@users.noreply.github.com>
Co-authored-by: MeowZheng <meowzheng@outlook.com>
Co-authored-by: Miao Zheng <76149310+MeowZheng@users.noreply.github.com>
wjkim81 pushed a commit to wjkim81/mmsegmentation that referenced this pull request Dec 3, 2023
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.

7 participants