-
Notifications
You must be signed in to change notification settings - Fork 965
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
Convert ResNet101 from TensorFlow to PyTorch #22
Comments
Hi @ahkarami , Tested with follow steps and some code addition.
$ wget http://download.tensorflow.org/models/resnet_v1_101_2016_08_28.tar.gz
$ tar -xvf resnet_v1_101_2016_08_28.tar.gz
I did it for you and you can refer this commit python -m mmdnn.conversion.examples.tensorflow.extract_model -n resnet_v1_101 -ckpt resnet_v1_101.ckpt
python -m mmdnn.conversion._script.convertToIR -f tensorflow -d kit_imagenet -n imagenet_resnet_v1_101.ckpt.meta --dstNodeName Squeeze -w imagenet_resnet_v1_101.ckpt
python -m mmdnn.conversion._script.IRToCode -f pytorch --IRModelPath kit_imagenet.pb --dstModelPath kit_imagenet.py --IRWeightPath kit_imagenet.npy -dw kit_pytorch.npy Currently you can use the kit_imagenet.py and kit_pytorch.npy to inference. And you can dump the original PyTorch model by next step.
$ python -m mmdnn.conversion.examples.pytorch.imagenet_test --dump resnet.pth -n kit_imagenet.py -w kit_pytorch.npy
PyTorch model file is saved as [resnet.pth], generated by [kit_imagenet.py] and [kit_pytorch.npy]. Done. |
PS: the readme of PyTorch is created. |
Dear @kitstar, |
Dear @kitstar,
Would you please help me to address this error? |
Hi, what is your tf version? I tested it with tf 1.3 and 1.4 and you can grep your tf package with "resnet_arg_scope" to find the namespace. |
Thank you. currently TF 1.1.0 has been installed on my system. I will upgrade it and test the conversion code again. |
@kitstar HI,What does it mean-> 'vgg19' : [(21, 0.37522122), (144, 0.28500062), (23, 0.099720284), (134, 0.036305398), (22, 0.033559237)], |
@namizzz i want to transform mobilenet_v2_1.4 model from tensorflow to pytorch,but i have no idea for that. |
Hi @DW1HH , refer to this: |
Thank you for your reply@namizzz |
I am sorry to bother you. @namizzz When the script finishes running,i get two files, mobilenet.pth and mobilenet.py ,but i can not load the mobilenet.pth , it's type-> <type 'long'>,not a dict. |
I have a tensorflow models produced by tensorflow1.14 , and there is no .ckpt files . There are model.data-00000-of-00001, model.index and model.meta instead . How can I transform them to .pt/.pkl files ? Could you help me ? URL for models https://github.com/StanfordSNR/indigo/tree/a9b2060d39e4da2e8987e893e3eca2a6c7cd0ab9/dagger/model |
I have completed the above steps and got a vgg16.pth file, however, when I used that in pytorch. I got the following errors: File "", line 1, in File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile File "E:/doc_dy/pytorch_deephash-master/train.py", line 8, in File "E:\doc_dy\pytorch_deephash-master\net_b.py", line 6, in File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torchvision\models\vgg.py", line 144, in vgg16 File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torchvision\models\vgg.py", line 92, in _vgg File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\hub.py", line 434, in load_state_dict_from_url File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\serialization.py", line 387, in load File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\serialization.py", line 574, in _load ModuleNotFoundError: No module named 'MainModel' |
I transfer the pretrained vgg16.ckpt in tensorflow to be used in pytorch. Because the pretrained vgg16.pth in pytorch is not trained enough. |
Dear @kitstar
WARNING:tensorflow:From /usr/local/python3.7.5/lib/python3.7/site-packages/mmdnn/conversion/examples/tensorflow/extract_model.py:23: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead. WARNING:tensorflow:From /usr/local/python3.7.5/lib/python3.7/site-packages/tensorflow_core/contrib/layers/python/layers/layers.py:1057: Layer.apply (from tensorflow.python.keras.engine.base_layer) is deprecated and will be removed in a future version. WARNING:tensorflow:From /usr/local/python3.7.5/lib/python3.7/site-packages/mmdnn/conversion/examples/tensorflow/extract_model.py:81: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead. 2020-08-11 16:31:03.102027: W tensorflow/core/platform/profile_utils/cpu_utils.cc:98] Failed to find bogomips in /proc/cpuinfo; cannot determine CPU frequency WARNING:tensorflow:From /usr/local/python3.7.5/lib/python3.7/site-packages/mmdnn/conversion/examples/tensorflow/extract_model.py:85: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead. 2020-08-11 16:31:14.165516: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: Key resnet_v2_50/block1/unit_1/bottleneck_v2/conv1/BatchNorm/beta not found in checkpoint |
hello,have you solved this problem? i have same question |
hello there, i am getting an error while converting my tf model to IR |
hello,have you solved this problem? i have same question |
Dear @kitstar,
I want to convert a ResNet V1 101 model (from TF-Slim) to PyTorch. Would you please kindly help me to do that?
Just as another suggestion, I think it would be great if you create a README.md file for PyTorch conversion section.
The text was updated successfully, but these errors were encountered: