Code Monkey home page Code Monkey logo

Comments (19)

kitstar avatar kitstar commented on May 2, 2024 26

Hi @ahkarami ,

Tested with follow steps and some code addition.

  1. Download resnet_v1_101 data
$ wget http://download.tensorflow.org/models/resnet_v1_101_2016_08_28.tar.gz
$ tar -xvf resnet_v1_101_2016_08_28.tar.gz
  1. Extract tf model files
    Refer the tensorflow model extractor to implement your own model extract code.

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
  1. Convert tf to IR
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
  1. Convert IR to Pytorch
    Please use argument -dw to extract the weight file for pytorch model saver
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.

  1. Dump the PyTorch model
$ 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.

from mmdnn.

kitstar avatar kitstar commented on May 2, 2024

PS: the readme of PyTorch is created.

from mmdnn.

ahkarami avatar ahkarami commented on May 2, 2024

Dear @kitstar,
Thank you very much for your complete answer. You are incredible!! 🥇

from mmdnn.

ahkarami avatar ahkarami commented on May 2, 2024

Dear @kitstar,
Thanks a lot for your complete and clear answer. However, unfortunately because I was so busy last 2 weeks, I couldn't test your answer. I Tested it today. At first I have downloaded the resnet_v1_101 data as you have mentioned. But, at the second step:
python -m mmdnn.conversion.examples.tensorflow.extract_model -n resnet_v1_101 -ckpt resnet_v1_101.ckpt
unfortunately I got this error:

Traceback (most recent call last):
  File "/home/karami/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/karami/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/karami/anaconda3/lib/python3.6/site-packages/mmdnn/conversion/examples/tensorflow/extract_model.py", line 36, in <module>
    'resnet50'      : resnet_v2.resnet_arg_scope,
AttributeError: module 'tensorflow.contrib.slim.python.slim.nets.resnet_v2' has no attribute 'resnet_arg_scope'

Would you please help me to address this error?

from mmdnn.

kitstar avatar kitstar commented on May 2, 2024

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.

from mmdnn.

ahkarami avatar ahkarami commented on May 2, 2024

Thank you. currently TF 1.1.0 has been installed on my system. I will upgrade it and test the conversion code again.

from mmdnn.

DW1HH avatar DW1HH commented on May 2, 2024

@kitstar HI,What does it mean-> 'vgg19' : [(21, 0.37522122), (144, 0.28500062), (23, 0.099720284), (134, 0.036305398), (22, 0.033559237)],

from mmdnn.

namizzz avatar namizzz commented on May 2, 2024

Hi @DW1HH , previously, the truth table is the results of imagenet image for test_truth function to test the accuracy of conversion. But we use tests/test_conversion_imagenet.py to check the accuracy.

from mmdnn.

DW1HH avatar DW1HH commented on May 2, 2024

@namizzz i want to transform mobilenet_v2_1.4 model from tensorflow to pytorch,but i have no idea for that.

from mmdnn.

namizzz avatar namizzz commented on May 2, 2024

Hi @DW1HH , refer to this:
mmconvert -sf tensorflow -iw resnet50v1_frozen.pb --inNodeName "input_tensor" --inputShape 224,224,3 --dstNodeName "softmax_tensor" -df pytorch -dw pytorch.npy -om resnet50v1.pth

from mmdnn.

DW1HH avatar DW1HH commented on May 2, 2024

Thank you for your reply@namizzz

from mmdnn.

DW1HH avatar DW1HH commented on May 2, 2024

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.

from mmdnn.

z6833 avatar z6833 commented on May 2, 2024

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

from mmdnn.

Yong-DAI avatar Yong-DAI commented on May 2, 2024

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
runfile('E:/doc_dy/pytorch_deephash-master/train.py', wdir='E:/doc_dy/pytorch_deephash-master')

File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)

File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "E:/doc_dy/pytorch_deephash-master/train.py", line 8, in
from net_b import AlexNetPlusLatent

File "E:\doc_dy\pytorch_deephash-master\net_b.py", line 6, in
alexnet_model = models.vgg16(pretrained=True) ### alexnet

File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torchvision\models\vgg.py", line 144, in vgg16
return _vgg('vgg16', 'D', False, pretrained, progress, **kwargs)

File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torchvision\models\vgg.py", line 92, in _vgg
progress=progress)

File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\hub.py", line 434, in load_state_dict_from_url
return torch.load(cached_file, map_location=map_location)

File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\serialization.py", line 387, in load
return _load(f, map_location, pickle_module, **pickle_load_args)

File "C:\Users\chddy\Anaconda3\envs\pytorch_gpu\lib\site-packages\torch\serialization.py", line 574, in _load
result = unpickler.load()

ModuleNotFoundError: No module named 'MainModel'

from mmdnn.

Yong-DAI avatar Yong-DAI commented on May 2, 2024

I transfer the pretrained vgg16.ckpt in tensorflow to be used in pytorch. Because the pretrained vgg16.pth in pytorch is not trained enough.

from mmdnn.

arya-none avatar arya-none commented on May 2, 2024

Dear @kitstar
Would you please kindly help me to find whats the problems as below? when i tried to extract resnet50 tf mode. The sincerity anticipates your reply,thanks!
[root@localhost model]# python3 -m mmdnn.conversion.examples.tensorflow.extract_model -n resnet50 -ckpt model.ckpt-450500
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:

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.
Instructions for updating:
Please use layer.__call__ method instead.
WARNING:tensorflow:From /usr/local/python3.7.5/lib/python3.7/site-packages/mmdnn/conversion/examples/tensorflow/extract_model.py:79: The name tf.global_variables_initializer is deprecated. Please use tf.compat.v1.global_variables_initializer instead.

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
2020-08-11 16:31:03.104051: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x26ad6f30 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-08-11 16:31:03.104152: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
WARNING:tensorflow:From /usr/local/python3.7.5/lib/python3.7/site-packages/mmdnn/conversion/examples/tensorflow/extract_model.py:82: The name tf.summary.FileWriter is deprecated. Please use tf.compat.v1.summary.FileWriter instead.

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
Traceback (most recent call last):
File "/usr/local/python3.7.5/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
return fn(*args)
File "/usr/local/python3.7.5/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn
target_list, run_metadata)
File "/usr/local/python3.7.5/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.NotFoundError: Key resnet_v2_50/block1/unit_1/bottleneck_v2/conv1/BatchNorm/beta not found in checkpoint
[[{{node save/RestoreV2}}]]

from mmdnn.

YIRuriZhongtian avatar YIRuriZhongtian commented on May 2, 2024

我有一个由tensorflow1.14生成的tensorflow模型,并且没有.ckpt文件。有model.data-00000-of-00001,model.index和model.meta代替。如何将它们转换为.pt / .pkl文件?你可以帮帮我吗 ?模型的网址https://github.com/StanfordSNR/indigo/tree/a9b2060d39e4da2e8987e893e3eca2a6c7cd0ab9/dagger/model

hello,have you solved this problem? i have same question

from mmdnn.

Rushikeshkoli15 avatar Rushikeshkoli15 commented on May 2, 2024

hello there, i am getting an error while converting my tf model to IR
AssertionError: Squeeze is not in graph
Could anyone help plz?

from mmdnn.

jsjy1 avatar jsjy1 commented on May 2, 2024

我有一个由tensorflow1.14生成的tensorflow模型,并且没有.ckpt文件。有model.data-00000-of-00001,model.index和model.meta代替。如何将它们转换为.pt / .pkl文件?你可以帮帮我吗 ?模型的网址https://github.com/StanfordSNR/indigo/tree/a9b2060d39e4da2e8987e893e3eca2a6c7cd0ab9/dagger/model

hello,have you solved this problem? i have same question

hello,have you solved this problem? i have same question

from mmdnn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.