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] Register torchvision transforms into mmcls #1265

Merged
merged 18 commits into from Apr 13, 2023

Conversation

Ezra-Yu
Copy link
Collaborator

@Ezra-Yu Ezra-Yu commented Dec 14, 2022

Motivation

Register torchvision transforms into mmcls

Modification

  1. Add stochastic depth decay rule in resnet refer to [Enhance] Add stochastic depth decay rule in resnet #1363
  2. Register torchvision transforms into mmcls;
  3. update transform NumpyToPIL and PILToNumpy;

Use cases

1. Use some vision Augs Surrounded by NumpyToPIL and 'PILToNumpy (Recommendation)

Surrounded by dict(type='NumpyToPIL', to_rgb=True), and dict(type='PILToNumpy', to_bgr=True),

train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='NumpyToPIL', to_rgb=True),     # from BGR in cv2 to RGB  in PIL
    dict(type='torchvision/RandomResizedCrop',size=176),
    dict(type='PILToNumpy', to_bgr=True),     # from RGB  in PIL to BGR in cv2
    dict(type='RandomFlip', prob=0.5, direction='horizontal'),
    dict(type='PackInputs'),
]

data_preprocessor = dict(
    num_classes=1000,
    mean=[123.675, 116.28, 103.53],
    std=[58.395, 57.12, 57.375],
    to_rgb=True,                          # from BGR in cv2 to RGB  in PIL
)

2. Use vision Augs and ToTensor&Normalize

Make sure have coverted to RGB-Numpy format; dict(type='NumpyToPIL', to_rgb=True)

train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='NumpyToPIL', to_rgb=True),       # from BGR in cv2 to RGB  in PIL
    dict(
        type='torchvision/RandomResizedCrop',
        size=176,
        interpolation=2),
    dict(type='torchvision/RandomHorizontalFlip', p=0.5),
    dict(
        type='torchvision/TrivialAugmentWide',
        interpolation=2),
    dict(type='torchvision/PILToTensor'),
    dict(type='torchvision/ConvertImageDtype', dtype=torch.float),
    dict(      
        type='torchvision/Normalize',  
        mean=(0.485, 0.456, 0.406),
        std=(0.229, 0.224, 0.225),
    ),
    dict(type='torchvision/RandomErasing', p=0.1),
    dict(type='PackInputs'),
]

data_preprocessor = dict(num_classes=1000, mean=None, std=None, to_rgb=False)  # Normalize in dataset pipeline

3. USe Augs but no ToTensor&Normalize

train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='NumpyToPIL', to_rgb=True),   # from BGR in cv2 to RGB  in PIL
    dict(type='torchvision/RandomResizedCrop', size=176, interpolation=2),
    dict(type='torchvision/RandomHorizontalFlip', p=0.5),
    dict(type='torchvision/TrivialAugmentWide', interpolation=2),
    dict(type='PackInputs'),
]

# here the Normalize params is for the RGB fromat
data_preprocessor = dict(
    num_classes=1000,
    mean=[123.675, 116.28, 103.53],
    std=[58.395, 57.12, 57.375],
    to_rgb=False,
)

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@Ezra-Yu Ezra-Yu changed the title [Feature] Register torchvision transforms into mmcls [WIP] [Feature] Register torchvision transforms into mmcls Dec 14, 2022
@codecov
Copy link

codecov bot commented Dec 14, 2022

Codecov Report

Patch coverage has no change and project coverage change: +0.85 🎉

Comparison is base (c9a0cb0) 84.37% compared to head (6663729) 85.22%.

❗ Current head 6663729 differs from pull request most recent head e9f53be. Consider uploading reports for the commit e9f53be to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1265      +/-   ##
==========================================
+ Coverage   84.37%   85.22%   +0.85%     
==========================================
  Files         142      229      +87     
  Lines        9925    17311    +7386     
  Branches     1621     2715    +1094     
==========================================
+ Hits         8374    14753    +6379     
- Misses       1277     2056     +779     
- Partials      274      502     +228     
Flag Coverage Δ
unittests 85.22% <ø> (+0.85%) ⬆️

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

see 371 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Ezra-Yu Ezra-Yu changed the title [WIP] [Feature] Register torchvision transforms into mmcls [Feature] Register torchvision transforms into mmcls Dec 14, 2022
@Ezra-Yu Ezra-Yu force-pushed the 1x_register_vision_transforms branch from f162ab1 to b4e24a1 Compare March 14, 2023 04:00
@Ezra-Yu Ezra-Yu changed the base branch from dev-1.x to main April 11, 2023 06:50
@Ezra-Yu Ezra-Yu force-pushed the 1x_register_vision_transforms branch from d81e078 to 0b818d6 Compare April 11, 2023 10:56
@fangyixiao18 fangyixiao18 changed the base branch from main to dev April 12, 2023 07:02
docs/en/api/data_process.rst Outdated Show resolved Hide resolved
docs/en/api/data_process.rst Outdated Show resolved Hide resolved
docs/en/api/data_process.rst Outdated Show resolved Hide resolved
@fangyixiao18 fangyixiao18 merged commit 99e4811 into open-mmlab:dev Apr 13, 2023
8 of 9 checks passed
@fangyixiao18 fangyixiao18 mentioned this pull request Apr 14, 2023
14 tasks
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

3 participants