Skip to content

[Feature] Support set dataloader args in config and and add function to handle config compatibility#7668

Merged
ZwwWayne merged 5 commits intoopen-mmlab:devfrom
jshilong:loader_args
Apr 20, 2022
Merged

[Feature] Support set dataloader args in config and and add function to handle config compatibility#7668
ZwwWayne merged 5 commits intoopen-mmlab:devfrom
jshilong:loader_args

Conversation

@jshilong
Copy link
Copy Markdown
Collaborator

@jshilong jshilong commented Apr 8, 2022

Describe the feature

  • Add train_dataloader, val_dataloader, and test_dataloader in the data field of config so that users can specify different arguments for them.
  • Add cfg_compatibility to handle the compatibility of config

Motivation

Originally, the data field of config only allows the following usage:

data = dict(
    samples_per_gpu=64, workers_per_gpu=4,
    train=dict(type='xxx', ...),
    val=dict(type='xxx', samples_per_gpu=4, ...),
    test=dict(type='xxx', ...),
)

Such a design only allows setting the different batch sizes in Val and test data loader.
Adding train_dataloader, val_dataloader, and test_dataloader in the data field of config allows more flexible usages.
A new example looks like below:

data = dict(
    train=dict(type='xxx', ...),
    val=dict(type='xxx', ...),
    test=dict(type='xxx', ...),
    # Use different batch size during inference.
    train_dataloader=dict(samples_per_gpu=64, workers_per_gpu=4),
    val_dataloader=dict(samples_per_gpu=8, workers_per_gpu=2),
    test_dataloader=dict(samples_per_gpu=8, workers_per_gpu=2),
)

To achieve that, we should:

allow train_dataloader/val_dataloader/test_dataloader to be set in the data filed by modifying train_detector.
deprecate samples_per_gpu in data.val field by raising warnings if it is set
Related resources
See PR open-mmlab/mmpretrain#752.

Midification

  1. modifying train_detector to allow passing args in the loader field to the build_dataloader
  2. Add a cfg_compatibility to handle the compatibility

BC

None

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2022

Codecov Report

Merging #7668 (8bd8b10) into dev (55a6fe1) will increase coverage by 0.17%.
The diff coverage is 69.33%.

@@            Coverage Diff             @@
##              dev    #7668      +/-   ##
==========================================
+ Coverage   64.76%   64.93%   +0.17%     
==========================================
  Files         346      348       +2     
  Lines       28162    28323     +161     
  Branches     4755     4778      +23     
==========================================
+ Hits        18238    18391     +153     
+ Misses       8962     8956       -6     
- Partials      962      976      +14     
Flag Coverage Δ
unittests 64.90% <69.33%> (+0.16%) ⬆️

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

Impacted Files Coverage Δ
mmdet/datasets/builder.py 54.83% <ø> (ø)
mmdet/apis/train.py 13.82% <11.11%> (+0.10%) ⬆️
mmdet/utils/setup_env.py 92.00% <60.00%> (-8.00%) ⬇️
mmdet/utils/compat_config.py 78.33% <78.33%> (ø)
mmdet/utils/__init__.py 100.00% <100.00%> (ø)
mmdet/datasets/dataset_wrappers.py 80.31% <0.00%> (-2.21%) ⬇️
mmdet/core/bbox/assigners/max_iou_assigner.py 72.36% <0.00%> (-1.32%) ⬇️
mmdet/core/hook/__init__.py 100.00% <0.00%> (ø)
mmdet/datasets/pipelines/__init__.py 100.00% <0.00%> (ø)
mmdet/core/hook/memory_profiler_hook.py 95.65% <0.00%> (ø)
... and 5 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 55a6fe1...8bd8b10. Read the comment docs.

Copy link
Copy Markdown
Collaborator

@ZwwWayne ZwwWayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invite @mzr1996 to take a look.

@jshilong jshilong changed the title [Feature]Add loader args to config [Feature] Support set dataloader args in config and and add functions to handle config compatibility Apr 14, 2022
@jshilong jshilong changed the title [Feature] Support set dataloader args in config and and add functions to handle config compatibility [Feature] Support set dataloader args in config and and add function to handle config compatibility Apr 14, 2022
@wlf-darkmatter
Copy link
Copy Markdown

Describe the feature

  • Add train_dataloader, val_dataloader, and test_dataloader in the data field of config so that users can specify different arguments for them.
  • Add cfg_compatibility to handle the compatibility of config

Motivation

Originally, the data field of config only allows the following usage:

data = dict(
    samples_per_gpu=64, workers_per_gpu=4,
    train=dict(type='xxx', ...),
    val=dict(type='xxx', samples_per_gpu=4, ...),
    test=dict(type='xxx', ...),
)

Such a design only allows setting the different batch sizes in Val and test data loader. Adding train_dataloader, val_dataloader, and test_dataloader in the data field of config allows more flexible usages. A new example looks like below:

data = dict(
    train=dict(type='xxx', ...),
    val=dict(type='xxx', ...),
    test=dict(type='xxx', ...),
    # Use different batch size during inference.
    train_dataloader=dict(samples_per_gpu=64, workers_per_gpu=4),
    val_dataloader=dict(samples_per_gpu=8, workers_per_gpu=2),
    test_dataloader=dict(samples_per_gpu=8, workers_per_gpu=2),
)

To achieve that, we should:

allow train_dataloader/val_dataloader/test_dataloader to be set in the data filed by modifying train_detector. deprecate samples_per_gpu in data.val field by raising warnings if it is set Related resources See PR open-mmlab/mmclassification#752.

Midification

  1. modifying train_detector to allow passing args in the loader field to the build_dataloader
  2. Add a cfg_compatibility to handle the compatibility

BC

None

It make an error raised when test_dataloader not inside cfg.data that

AttributeError: 'ConfigDict' object has no attribute 'test_dataloader'

it wou better to add an if to tell if the cfg.data get the attribute test_dataloader to avoid error.

ZwwWayne pushed a commit that referenced this pull request Jul 18, 2022
…to handle config compatibility (#7668)

* add cfg_compatibility and support loader args

* resolve comments

* add unitest

* resolve comments

* delete all warning
ZwwWayne pushed a commit to ZwwWayne/mmdetection that referenced this pull request Jul 19, 2022
…to handle config compatibility (open-mmlab#7668)

* add cfg_compatibility and support loader args

* resolve comments

* add unitest

* resolve comments

* delete all warning
SakiRinn pushed a commit to SakiRinn/mmdetection-locount that referenced this pull request Mar 17, 2023
…to handle config compatibility (open-mmlab#7668)

* add cfg_compatibility and support loader args

* resolve comments

* add unitest

* resolve comments

* delete all warning
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.

8 participants