Open caesar84 opened 5 years ago
Hi @caesar84, could you upload your model for us to debug? Thanks!
hi @rainLiuplus I have tried to upload the model ( Prototxt and caffemodel files ) But they are too big as the caffemodel file is about 44 Mb. so, could you please download the files from the official Nvidia team here : https://raw.githubusercontent.com/NVIDIA-AI-IOT/redtail/master/models/pretrained/TrailNet_SResNet-18.prototxt
I am thankful for your effort and I would appreciate it if you would be able to convert it to a Keras or ONNX model .
Hi @caesar84, the caffe [Scale] has been added, please check the lastest master.
After clone it, you could run below script at the root of your MMdnn folder:
export PYTHONPATH=.
python -m mmdnn.conversion._script.convert -sf caffe -in TrailNet_SResNet-18.prototxt -iw TrailNet_SResNet-18.caffemodel -df keras -om TrailNet_SResNet-18.h5
hi @rainLiuplus thanks for your reply I do really appreciate it. I followed your instructions and here is the output
` WARNING: PyCaffe not found! Falling back to a pure protocol buffer implementation.
Data data -- (1, 3, 180, 320) Scale sub_mean (1, 1, 1, 3) (1, 3, 180, 320) Convolution conv1 (7, 7, 3, 64) (1, 64, 87, 157) Scale conv1_srelu1_1 (1, 1, 1, 64) (1, 64, 87, 157) ReLU conv1_srelu1_2 -- (1, 64, 87, 157) Scale conv1_srelu1_3 (1, 1, 1, 64) (1, 64, 87, 157) Pooling pool1 -- (1, 64, 43, 78) Convolution res1_1_1 (3, 3, 64, 64) (1, 64, 43, 78) Scale res1_1_1_srelu_1 (1, 1, 1, 64) (1, 64, 43, 78) ReLU res1_1_1_srelu_2 -- (1, 64, 43, 78) Scale res1_1_1_srelu_3 (1, 1, 1, 64) (1, 64, 43, 78) Convolution res1_1_2 (3, 3, 64, 64) (1, 64, 43, 78) Eltwise res1_1_sum -- (1, 64, 43, 78) Scale res1_1_srelu_1 (1, 1, 1, 64) (1, 64, 43, 78) ReLU res1_1_srelu_2 -- (1, 64, 43, 78) Scale res1_1_srelu_3 (1, 1, 1, 64) (1, 64, 43, 78) Convolution res1_2_1 (3, 3, 64, 64) (1, 64, 43, 78) Scale res1_2_1_srelu_1 (1, 1, 1, 64) (1, 64, 43, 78) ReLU res1_2_1_srelu_2 -- (1, 64, 43, 78) Scale res1_2_1_srelu_3 (1, 1, 1, 64) (1, 64, 43, 78) Convolution res1_2_2 (3, 3, 64, 64) (1, 64, 43, 78) Eltwise res1_2_sum -- (1, 64, 43, 78) Scale res1_2_srelu_1 (1, 1, 1, 64) (1, 64, 43, 78) ReLU res1_2_srelu_2 -- (1, 64, 43, 78) Scale res1_2_srelu_3 (1, 1, 1, 64) (1, 64, 43, 78) Convolution res2_1_1 (3, 3, 64, 128) (1, 128, 43, 78) Scale res2_1_1_srelu_1 (1, 1, 1, 128) (1, 128, 43, 78) ReLU res2_1_1_srelu_2 -- (1, 128, 43, 78) Scale res2_1_1_srelu_3 (1, 1, 1, 128) (1, 128, 43, 78) Convolution res2_1_2 (3, 3, 128, 128) (1, 128, 22, 39) Convolution res2_1_proj (1, 1, 64, 128) (1, 128, 22, 39) Eltwise res2_1_sum -- (1, 128, 22, 39) Scale res2_1_srelu_1 (1, 1, 1, 128) (1, 128, 22, 39) ReLU res2_1_srelu_2 -- (1, 128, 22, 39) Scale res2_1_srelu_3 (1, 1, 1, 128) (1, 128, 22, 39) Convolution res2_2_1 (3, 3, 128, 128) (1, 128, 22, 39) Scale res2_2_1_srelu_1 (1, 1, 1, 128) (1, 128, 22, 39) ReLU res2_2_1_srelu_2 -- (1, 128, 22, 39) Scale res2_2_1_srelu_3 (1, 1, 1, 128) (1, 128, 22, 39) Convolution res2_2_2 (3, 3, 128, 128) (1, 128, 22, 39) Eltwise res2_2_sum -- (1, 128, 22, 39) Scale res2_2_srelu_1 (1, 1, 1, 128) (1, 128, 22, 39) ReLU res2_2_srelu_2 -- (1, 128, 22, 39) Scale res2_2_srelu_3 (1, 1, 1, 128) (1, 128, 22, 39) Convolution res3_1_1 (3, 3, 128, 256) (1, 256, 22, 39) Scale res3_1_1_srelu_1 (1, 1, 1, 256) (1, 256, 22, 39) ReLU res3_1_1_srelu_2 -- (1, 256, 22, 39) Scale res3_1_1_srelu_3 (1, 1, 1, 256) (1, 256, 22, 39) Convolution res3_1_2 (3, 3, 256, 256) (1, 256, 11, 20) Convolution res3_1_proj (1, 1, 128, 256) (1, 256, 11, 20) Eltwise res3_1_sum -- (1, 256, 11, 20) Scale res3_1_srelu_1 (1, 1, 1, 256) (1, 256, 11, 20) ReLU res3_1_srelu_2 -- (1, 256, 11, 20) Scale res3_1_srelu_3 (1, 1, 1, 256) (1, 256, 11, 20) Convolution res3_2_1 (3, 3, 256, 256) (1, 256, 11, 20) Scale res3_2_1_srelu_1 (1, 1, 1, 256) (1, 256, 11, 20) ReLU res3_2_1_srelu_2 -- (1, 256, 11, 20) Scale res3_2_1_srelu_3 (1, 1, 1, 256) (1, 256, 11, 20) Convolution res3_2_2 (3, 3, 256, 256) (1, 256, 11, 20) Eltwise res3_2_sum -- (1, 256, 11, 20) Scale res3_2_srelu_1 (1, 1, 1, 256) (1, 256, 11, 20) ReLU res3_2_srelu_2 -- (1, 256, 11, 20) Scale res3_2_srelu_3 (1, 1, 1, 256) (1, 256, 11, 20) Convolution res4_1_1 (3, 3, 256, 512) (1, 512, 11, 20) Scale res4_1_1_srelu_1 (1, 1, 1, 512) (1, 512, 11, 20) ReLU res4_1_1_srelu_2 -- (1, 512, 11, 20) Scale res4_1_1_srelu_3 (1, 1, 1, 512) (1, 512, 11, 20) Convolution res4_1_2 (3, 3, 512, 512) (1, 512, 6, 10) Convolution res4_1_proj (1, 1, 256, 512) (1, 512, 6, 10) Eltwise res4_1_sum -- (1, 512, 6, 10) Scale res4_1_srelu_1 (1, 1, 1, 512) (1, 512, 6, 10) ReLU res4_1_srelu_2 -- (1, 512, 6, 10) Scale res4_1_srelu_3 (1, 1, 1, 512) (1, 512, 6, 10) Convolution res4_2_1 (3, 3, 512, 512) (1, 512, 6, 10) Scale res4_2_1_srelu_1 (1, 1, 1, 512) (1, 512, 6, 10) ReLU res4_2_1_srelu_2 -- (1, 512, 6, 10) Scale res4_2_1_srelu_3 (1, 1, 1, 512) (1, 512, 6, 10) Convolution res4_2_2 (3, 3, 512, 512) (1, 512, 6, 10) Eltwise res4_2_sum -- (1, 512, 6, 10) Scale res4_2_srelu_1 (1, 1, 1, 512) (1, 512, 6, 10) ReLU res4_2_srelu_2 -- (1, 512, 6, 10) Scale res4_2_srelu_3 (1, 1, 1, 512) (1, 512, 6, 10) Pooling pool_avg -- (1, 512, 4, 8) InnerProduct fc3 (16384, 3) (1, 3, 1, 1) Softmax softmax -- (1, 3, 1, 1) InnerProduct fc3_t (16384, 3) (1, 3, 1, 1) Softmax softmax_t -- (1, 3, 1, 1) Concat concat -- (1, 6, 1, 1) IR network structure is saved as [434fc6be41ab4938895410494cc57767.json]. IR network structure is saved as [434fc6be41ab4938895410494cc57767.pb]. IR weights are saved as [434fc6be41ab4938895410494cc57767.npy]. Using TensorFlow backend. Parse file [434fc6be41ab4938895410494cc57767.pb] with binary format successfully. Target network code snippet is saved as [434fc6be41ab4938895410494cc57767.py]. WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:3976: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:3980: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.
434fc6be41ab4938895410494cc57767.py:47: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison if 'weights' in cur_dict: 434fc6be41ab4938895410494cc57767.py:49: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison if 'bias' in cur_dict: WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:174: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py:181: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.
2019-09-11 16:15:35.674816: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-09-11 16:15:35.682960: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3599995000 Hz
2019-09-11 16:15:35.683149: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2dbfac0 executing computations on platform Host. Devices:
2019-09-11 16:15:35.683202: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0):
Although it did manage to create IR version of the Network, I still encounter a couple of errors.
I guess you tried the new code on the TrailNet_SResNet-18 for testing, would it be possible for you to share with me the converted Keras model so I can try to import it into Matlab? if so I would be so grateful. I have to try import Keras and ONNX models of the same network in case anyone might not work so your help is appreciated in advance.
Here is the model: https://drive.google.com/open?id=1czn6DqAoCoin_ev3W2Kp5ktniwxlJnh-
But I could successfully convert the model in local, like
May I ask your keras version?
Thanks!
hi @rainLiuplus firstly, thank you for your great help and quick response. Basically, I am trying to convert the original Caffe model into Matlab model. This can be done via importing either caffe, Keras or ONNX model. Caffe importer has some limitations in Matlab so I moved to Keras and ONNX. I tried to use your Keras resulted model but unfortunately, it gave me an error which has been reported to Matlab support already for a possible solution. Next, I tried again to convert the Keras model to ONNX then see if Matlab can import it successfully. I tried https://github.com/onnx/onnx-docker and it didn't go very well. I will post the images of the error here if you are interested. Also, I tried this https://github.com/onnx/keras-onnx and still no progress.
I dont know what to do else at the moment.
Platform (like ubuntu 16.04/win10):
Python version:
Source framework with version (like Tensorflow 1.4.1 with GPU):
Destination framework with version (like CNTK 2.3 with GPU):
Pre-trained model path (webpath or webdisk
path):
TrailNet_SResNet-18 Running scripts: root@88d618bfdf67:/mmdnn# mmconvert -sf caffe -in TrailNet_SResNet-18.prototxt -iw TrailNet_SResNet-18.caffemodel -df keras -om TrailNet_SResNet-18.h5i run the above command to convert a pre-trained model (TrailNet_SResNet-18 ) to keras after installing the docker CE per installations instaructions. i have this error :
WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale WARNING: Unhandled parameters: Scale Type Name Param Output
Data data -- (1, 3, 180, 320) Scale sub_mean (3,) (1, 3, 180, 320) Convolution conv1 (7, 7, 3, 64) (1, 64, 87, 157) Scale conv1_srelu1_1 (64,) (1, 64, 87, 157) ReLU conv1_srelu1_2 -- (1, 64, 87, 157) Scale conv1_srelu1_3 (64,) (1, 64, 87, 157) Pooling pool1 -- (1, 64, 43, 78) Convolution res1_1_1 (3, 3, 64, 64) (1, 64, 43, 78) Scale res1_1_1_srelu_1 (64,) (1, 64, 43, 78) ReLU res1_1_1_srelu_2 -- (1, 64, 43, 78) Scale res1_1_1_srelu_3 (64,) (1, 64, 43, 78) Convolution res1_1_2 (3, 3, 64, 64) (1, 64, 43, 78) Eltwise res1_1_sum -- (1, 64, 43, 78) Scale res1_1_srelu_1 (64,) (1, 64, 43, 78) ReLU res1_1_srelu_2 -- (1, 64, 43, 78) Scale res1_1_srelu_3 (64,) (1, 64, 43, 78) Convolution res1_2_1 (3, 3, 64, 64) (1, 64, 43, 78) Scale res1_2_1_srelu_1 (64,) (1, 64, 43, 78) ReLU res1_2_1_srelu_2 -- (1, 64, 43, 78) Scale res1_2_1_srelu_3 (64,) (1, 64, 43, 78) Convolution res1_2_2 (3, 3, 64, 64) (1, 64, 43, 78) Eltwise res1_2_sum -- (1, 64, 43, 78) Scale res1_2_srelu_1 (64,) (1, 64, 43, 78) ReLU res1_2_srelu_2 -- (1, 64, 43, 78) Scale res1_2_srelu_3 (64,) (1, 64, 43, 78) Convolution res2_1_1 (3, 3, 64, 128) (1, 128, 43, 78) Scale res2_1_1_srelu_1 (128,) (1, 128, 43, 78) ReLU res2_1_1_srelu_2 -- (1, 128, 43, 78) Scale res2_1_1_srelu_3 (128,) (1, 128, 43, 78) Convolution res2_1_2 (3, 3, 128, 128) (1, 128, 22, 39) Convolution res2_1_proj (1, 1, 64, 128) (1, 128, 22, 39) Eltwise res2_1_sum -- (1, 128, 22, 39) Scale res2_1_srelu_1 (128,) (1, 128, 22, 39) ReLU res2_1_srelu_2 -- (1, 128, 22, 39) Scale res2_1_srelu_3 (128,) (1, 128, 22, 39) Convolution res2_2_1 (3, 3, 128, 128) (1, 128, 22, 39) Scale res2_2_1_srelu_1 (128,) (1, 128, 22, 39) ReLU res2_2_1_srelu_2 -- (1, 128, 22, 39) Scale res2_2_1_srelu_3 (128,) (1, 128, 22, 39) Convolution res2_2_2 (3, 3, 128, 128) (1, 128, 22, 39) Eltwise res2_2_sum -- (1, 128, 22, 39) Scale res2_2_srelu_1 (128,) (1, 128, 22, 39) ReLU res2_2_srelu_2 -- (1, 128, 22, 39) Scale res2_2_srelu_3 (128,) (1, 128, 22, 39) Convolution res3_1_1 (3, 3, 128, 256) (1, 256, 22, 39) Scale res3_1_1_srelu_1 (256,) (1, 256, 22, 39) ReLU res3_1_1_srelu_2 -- (1, 256, 22, 39) Scale res3_1_1_srelu_3 (256,) (1, 256, 22, 39) Convolution res3_1_2 (3, 3, 256, 256) (1, 256, 11, 20) Convolution res3_1_proj (1, 1, 128, 256) (1, 256, 11, 20) Eltwise res3_1_sum -- (1, 256, 11, 20) Scale res3_1_srelu_1 (256,) (1, 256, 11, 20) ReLU res3_1_srelu_2 -- (1, 256, 11, 20) Scale res3_1_srelu_3 (256,) (1, 256, 11, 20) Convolution res3_2_1 (3, 3, 256, 256) (1, 256, 11, 20) Scale res3_2_1_srelu_1 (256,) (1, 256, 11, 20) ReLU res3_2_1_srelu_2 -- (1, 256, 11, 20) Scale res3_2_1_srelu_3 (256,) (1, 256, 11, 20) Convolution res3_2_2 (3, 3, 256, 256) (1, 256, 11, 20) Eltwise res3_2_sum -- (1, 256, 11, 20) Scale res3_2_srelu_1 (256,) (1, 256, 11, 20) ReLU res3_2_srelu_2 -- (1, 256, 11, 20) Scale res3_2_srelu_3 (256,) (1, 256, 11, 20) Convolution res4_1_1 (3, 3, 256, 512) (1, 512, 11, 20) Scale res4_1_1_srelu_1 (512,) (1, 512, 11, 20) ReLU res4_1_1_srelu_2 -- (1, 512, 11, 20) Scale res4_1_1_srelu_3 (512,) (1, 512, 11, 20) Convolution res4_1_2 (3, 3, 512, 512) (1, 512, 6, 10) Convolution res4_1_proj (1, 1, 256, 512) (1, 512, 6, 10) Eltwise res4_1_sum -- (1, 512, 6, 10) Scale res4_1_srelu_1 (512,) (1, 512, 6, 10) ReLU res4_1_srelu_2 -- (1, 512, 6, 10) Scale res4_1_srelu_3 (512,) (1, 512, 6, 10) Convolution res4_2_1 (3, 3, 512, 512) (1, 512, 6, 10) Scale res4_2_1_srelu_1 (512,) (1, 512, 6, 10) ReLU res4_2_1_srelu_2 -- (1, 512, 6, 10) Scale res4_2_1_srelu_3 (512,) (1, 512, 6, 10) Convolution res4_2_2 (3, 3, 512, 512) (1, 512, 6, 10) Eltwise res4_2_sum -- (1, 512, 6, 10) Scale res4_2_srelu_1 (512,) (1, 512, 6, 10) ReLU res4_2_srelu_2 -- (1, 512, 6, 10) Scale res4_2_srelu_3 (512,) (1, 512, 6, 10) Pooling pool_avg -- (1, 512, 4, 8) InnerProduct fc3 (16384, 3) (1, 3, 1, 1) Softmax softmax -- (1, 3, 1, 1) InnerProduct fc3_t (16384, 3) (1, 3, 1, 1) Softmax softmax_t -- (1, 3, 1, 1) Concat concat -- (1, 6, 1, 1) Traceback (most recent call last): File "/usr/local/bin/mmconvert", line 11, in
sys.exit(_main())
File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/_script/convert.py", line 102, in _main
ret = convertToIR._convert(ir_args)
File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/_script/convertToIR.py", line 10, in _convert
graph = transformer.transform_graph()
File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/caffe/transformer.py", line 360, in transform_graph
mapped_node = self.map_node(node)
File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/caffe/transformer.py", line 381, in map_node
mapped_node = map_func(node)
File "/usr/local/lib/python3.5/dist-packages/mmdnn/conversion/caffe/mapper.py", line 237, in map_scale
raise NotImplementedError
NotImplementedError
Anyone can help me if I wrote the command wrongly? or its another issue?
ps, i had cut the first part of the output because it was ok .