日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

mmdnn tensorflow 转 caffe

發(fā)布時(shí)間:2023/12/4 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mmdnn tensorflow 转 caffe 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

參考

https://github.com/Microsoft/MMdnn/blob/master/mmdnn/conversion/tensorflow/README.md#how-to-prepare-your-model-and-conversion-parameters

查看可用模型:

How to prepare your model and conversion parameters

You can refer?Slim Model Extractor?to extract your own tensorflow model, which is a sample tool to extract both architecture and weights from slim pre-trained models.

$ mmdownload -f tensorflowSupport frameworks: ['inception_v3_frozen', 'resnet_v2_200', 'inception_v1', 'mobilenet_v1_1.0', 'mobilenet_v2_1.0_224', 'resnet_v2_152', 'vgg16', 'mobilenet_v1_1.0_frozen', 'resnet_v1_50', 'resnet_v2_50', 'inception_v3', 'inception_resnet_v2', 'resnet_v1_152', 'inception_v1_frozen', 'vgg19', 'nasnet-a_large']

有幾條路:

1. ckpt 轉(zhuǎn)

Checkpoint File Conversion

We will give an example to convert TensorFlow?resnet?slim model with checkpoint files to?caffe.

# Download TensorFlow pre-trained model first $ mmdownload -f tensorflow -n resnet_v2_152Downloading file [./resnet_v2_152_2017_04_14.tar.gz] from [http://download.tensorflow.org/models/resnet_v2_152_2017_04_14.tar.gz] 100% [......................................................................] 675629399 / 675629399 Model saved in file: ./imagenet_resnet_v2_152.ckpt# Convert the TensorFlow model to Caffe $ mmconvert -sf tensorflow -in imagenet_resnet_v2_152.ckpt.meta -iw imagenet_resnet_v2_152.ckpt --dstNodeName MMdnn_Output -df caffe -om tf_resnet . . Caffe model files are saved as [tf_resnet.prototxt] and [tf_resnet.caffemodel], generated by [203e03ef187a42f59942737dace8773d.py] and [203e03ef187a42f59942737dace8773d.npy].

-in?is used to specify the ".ckpt.meta" file.

-iw?is used to specify the ".ckpt" file.

--dstNodeName?is used to specify the output node of your model, which can be found in your code or tensorboard graph. We provide a tool?vis_meta?to help visualize your meta graph.

2. frozen pb 轉(zhuǎn)

We will give an example to convert TensorFlow?mobilenet?slim model with frozen_pb to?caffe

# Download TensorFlow pre-trained model first $ mmdownload -f tensorflow -n mobilenet_v1_1.0_frozenDownloading file [mobilenet_v1_1.0_224_frozen.tgz] from [https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_1.0_224_frozen.tgz] progress: 18712.0 KB downloaded, 100%k# Convert the TensorFlow model to Caffe $ mmconvert -sf tensorflow -iw mobilenet_v1_1.0_224/frozen_graph.pb --inNodeName input --inputShape 224,224,3 --dstNodeName MobilenetV1/Predictions/Softmax -df caffe -om tf_mobilenet . . Caffe model files are saved as [tf_mobilenet.prototxt] and [tf_mobilenet.caffemodel], generated by [e96550a4c55141afa8cd94372b858613.py] and [e96550a4c55141afa8cd94372b858613.npy].

For frozen graph parser,?--inNodeName?and?--inputShape?are required, and don't need to set?-in.

3. debug 模式一步一步來(lái)

Step-by-step conversion for debugging

We will give an example to convert TensorFlow?mobilenet?slim model with frozen_pb to?caffe.

# Convert frozen graph to IR $ mmtoir -f tensorflow -w mobilenet_v1_1.0_224/frozen_graph.pb --inNodeName input --inputShape 224,224,3 --dstNodeName MobilenetV1/Predictions/Softmax -o mobilenet_v1IR network structure is saved as [mobilenet_v1.json]. IR network structure is saved as [mobilenet_v1.pb]. IR weights are saved as [mobilenet_v1.npy].# Convert IR to Caffe network building code $ mmtocode -f caffe -n mobilenet_v1.pb -w mobilenet_v1.npy -o tf_mobilenet.py -ow tf_mobilenet.npyParse file [mobilenet_v1.pb] with binary format successfully. Target network code snippet is saved as [tf_mobilenet.py]. Target weights are saved as [tf_mobilenet.npy].# Use Caffe network building code to generate an original Caffe model $ mmtomodel -f caffe -in tf_mobilenet.py -iw tf_mobilenet.npy -o tf_mobilenet . . . Caffe model files are saved as [tf_mobilenet.prototxt] and [tf_mobilenet.caffemodel], generated by [tf_mobilenet.py] and [tf_mobilenet.npy].

The you can use?tf_mobilenet.prototxt?and?tf_mobilenet.caffemodel?in Caffe directly.

第三個(gè)方法的好處是,如果前兩條路出現(xiàn)cuda error,可以用debug模式一步一步來(lái)減輕GPU的負(fù)擔(dān)從而解決問(wèn)題。

常見(jiàn)問(wèn)題是

DummyData 出現(xiàn) "'LayerParameter' object has no attribute 'shape'" 在 _to_proto 的時(shí)候,

解決辦法:caffe在dummydata 進(jìn)行了更新,我們也需要更新caffe并重新 make pycaffe

?

?

總結(jié)

以上是生活随笔為你收集整理的mmdnn tensorflow 转 caffe的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。