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] Support Wide ResNet #715

Merged
merged 7 commits into from
Mar 4, 2022
Merged

[Feature] Support Wide ResNet #715

merged 7 commits into from
Mar 4, 2022

Conversation

yasu0001
Copy link
Contributor

@yasu0001 yasu0001 commented Mar 2, 2022

Motivation

Based on #678

Modification

Add two wide resnet config files for ImageNet.

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2022

CLA assistant check
All committers have signed the CLA.

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Mar 2, 2022

Thank you for your contribution to mmclassification. Please sign the CLA license so that we can review your code.

We notice there are checkpoints for wide resnet. Could you use the script(as below) to convert torchvison ckpt into mmcls ckpt and make sure that the inference accuracy in Imagnet-1k are the same?

after convert and prepare the magnet-1k val dataset. run

python ./tools/test.py PATH_TO_WIDERESNET CKPT_PATH --metrics accuracy

torchvison_to_mmcls.py

import argparse
from collections import OrderedDict
from pathlib import Path

import torch


def convert(src, dst):
    print('Converting...')
    blobs = torch.load(src, map_location='cpu')
    converted_state_dict = OrderedDict()

    for key, value in blobs.items():
        if not key.startswith('fc'):
            converted_state_dict['backbone.' + key] = value
        else:
            converted_state_dict['head.' + key] = value

    torch.save(converted_state_dict, dst)
    print('Done!')


def main():
    parser = argparse.ArgumentParser(description='Convert model keys')
    parser.add_argument('src', help='src detectron model path')
    parser.add_argument('dst', help='save path')
    args = parser.parse_args()

    dst = Path(args.dst)
    if dst.suffix != '.pth':
        print('The path should contain the name of the pth format file.')
        exit()
    dst.parent.mkdir(parents=True, exist_ok=True)

    convert(args.src, args.dst)


if __name__ == '__main__':
    main()

@yasu0001
Copy link
Contributor Author

yasu0001 commented Mar 2, 2022

I've confirmed that the accuracy is almost same after model conversion.
The accuracy of torchvision is cited from https://pytorch.org/vision/stable/models.html

Model Accs@1 Accs@1(torchvision) Accs@5 Accs@5(torchvision)
Wide ResNet 50 77.7 78.47 93.79 94.09
Wide ResNet 101 78.18 78.85 93.98 94.28
ResNet 50 75.36 76.130 92.52 92.862

I would like to ask you about CLA.
The status of CLA is still pending after agreement the License.
This may be because I used wrong mail address in git.config when I pushed.
What I should do in this case?

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Mar 2, 2022

I've confirmed that the accuracy is almost same after model conversion. The accuracy of torchvision is cited from https://pytorch.org/vision/stable/models.html

Actually, the accuracy should be the same. So there is something different with setting in torchvision. Maybe it causes by Resize backend, You can try:

dict(type='Resize', size=(256, -1), backend='pillow'),

This may be because I used wrong mail address in git.config when I pushed.

Did you mean that you have pushed your commits before config your email address, which caused the username unable to be tracked? Maybe you need to use git rebase to modify your commit information. Or just close this PR and re-create a new one.

@yasu0001
Copy link
Contributor Author

yasu0001 commented Mar 2, 2022

Actually, the accuracy should be the same. So there is something different with setting in torchvision. Maybe it causes by Resize backend, You can try:
dict(type='Resize', size=(256, -1), backend='pillow'),

I confirmed the accuracy is the same as torchvision by modifying resize backend.

Model Accs@1 Accs@1(torchvision) Accs@5 Accs@5(torchvision)
Wide ResNet 50 78.48 78.47 94.08 94.09
Wide ResNet 101 78.84 78.85 94.28 94.28
ResNet 50 76.14 76.13 92.87 92.86

Did you mean that you have pushed your commits before config your email address, which caused the username unable to be tracked? Maybe you need to use git rebase to modify your commit information. Or just close this PR and re-create a new one.

Yes, I modified commit message.

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Mar 2, 2022

Great! Please update the configs.

Later, I will add some docs about wide-ResNet. Could I just commit to your branch directly?

@yasu0001
Copy link
Contributor Author

yasu0001 commented Mar 2, 2022

Later, I will add some docs about wide-ResNet. Could I just commit to your branch directly?

Sure! please.

@mzr1996 mzr1996 changed the base branch from master to dev March 3, 2022 05:10
@Ezra-Yu Ezra-Yu mentioned this pull request Mar 3, 2022
27 tasks
@Ezra-Yu Ezra-Yu changed the title Support Wide ResNet [Feature] Support Wide ResNet Mar 3, 2022
@codecov
Copy link

codecov bot commented Mar 3, 2022

Codecov Report

Merging #715 (62bae69) into dev (c708770) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     #715   +/-   ##
=======================================
  Coverage   84.94%   84.94%           
=======================================
  Files         121      121           
  Lines        7548     7548           
  Branches     1303     1303           
=======================================
  Hits         6412     6412           
  Misses        944      944           
  Partials      192      192           
Flag Coverage Δ
unittests 84.87% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out 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 c708770...62bae69. Read the comment docs.

Copy link
Member

@mzr1996 mzr1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@mzr1996 mzr1996 merged commit 779a062 into open-mmlab:dev Mar 4, 2022
@Davidgzx
Copy link

No support for 3 stage WRN? like WRN 16 to WRN 40?

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Mar 10, 2022

@Davidgzx Can you attach the code and weights link?

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Mar 10, 2022

@Davidgzx In the official repo, the wrn16 or the wrn40 are trained by using cifra10 and cifra100. I think the ImagNet-1k dataset is more general.

@Ezra-Yu Ezra-Yu mentioned this pull request Apr 21, 2022
mzr1996 added a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
* Add configs of Wide ResNet

* updated config

* add docs and metafile

* update configs

* remove extra import

* Update metafile and readme

Co-authored-by: Ezra-Yu <1105212286@qq.com>
Co-authored-by: mzr1996 <mzr1996@163.com>
@OpenMMLab-Assistant003
Copy link

Hi @yasu0001!First of all, we want to express our gratitude for your significant PR in the MMClassification project. Your contribution is highly appreciated, and we are grateful for your efforts in helping improve this open-source project during your personal time. We believe that many developers will benefit from your PR.

We would also like to invite you to join our Special Interest Group (SIG) private channel on Discord, where you can share your experiences, ideas, and build connections with like-minded peers. To join the SIG channel, simply message moderator— OpenMMLab on Discord or briefly share your open-source contributions in the #introductions channel and we will assist you. Look forward to seeing you there! Join us :https://discord.gg/UjgXkPWNqA

If you have WeChat account,welcome to join our community on WeChat. You can add our assistant :openmmlabwx. Please add "mmsig + Github ID" as a remark when adding friends:)
Thank you again for your contribution❤ @yasu0001

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.

6 participants