open-mmlab / mmpretrain

OpenMMLab Pre-training Toolbox and Benchmark
https://mmpretrain.readthedocs.io/en/latest/
Apache License 2.0
3.49k stars 1.08k forks source link

[Bug] There are differences between resnet18 implemented by the current mmcls framework and officially pytorch! #1597

Open tensorflowt opened 1 year ago

tensorflowt commented 1 year ago

分支

main 分支 (mmpretrain 版本)

描述该错误

Currently, I have completed a resnet18 classification model based on mmcls training. The reference cfg is as follows: https://github.com/open-mmlab/mmpretrain/blob/main/configs/resnet/resnet18_8xb32_in1k.py After I have trained the model, I need to deploy it on the edge of the chip. However, the resnet18 currently supported by this chip is based on the network structure officially implemented by pytorch. Its structure is as follows: ResNet.txt The pth model corresponding to this network is officially provided by pytorch as follows: https://download.pytorch.org/models/resnet18-5c106cde.pth The source of the pth model of resnet18 of mmcls I compared is as follows: https://mmpretrain.readthedocs.io/en/latest/papers/resnet.html my question: What do I need to do with the pth under the mmcls framework to get a new pth model so that the pth model can match the official resnet18 model of pytorch? thks!

环境信息

no thing

其他信息

No response

Ezra-Yu commented 1 year ago

So, where is the difference?

tensorflowt commented 1 year ago

The specific error is as follows error What I understand is that the parameter information saved in the pth model file of mmcls training is inconsistent with the parameter information saved in the pth model file of pytorch, so the model parameter analysis cannot be performed through the resnet18 model file of pytorch.

So, if I want to modify the model trained by mmcls so that it can be successfully parsed by pytorch's resnet18. What conversion do I need to do?

Ezra-Yu commented 1 year ago

here is the torchvision_2_mmpretrain.py script, you can refer it and convert the model from mmpretrain to torchvision. There is also a tool that can help you check the key name of the weight. https://github.com/open-mmlab/mmpretrain/blob/main/.dev_scripts/ckpt_tree.py

tensorflowt commented 1 year ago

ok,thks. I will try the method you provided.