mmdnn tensorflow 转 caffe
參考
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)題。
- 上一篇: error: ‘CUDNN_CONVOL
- 下一篇: Deeplab unexpected l