Convert ***.caffemodel to ***.mlmodel failed!

I have used the already trained caffemodel through coremltools to convert to mlmodel failed!


My conversion code:


import coremltools

# Convert a caffe model to a classifier in Core ML

caffe_model = ('TextBoxes_icdar13.caffemodel', 'deploy.prototxt')

coreml_model = coremltools.converters.caffe.convert(

caffe_model,

image_input_names='data'

)

# Now save the model

coreml_model.save('TextBoxes_icdar13.mlmodel')



The error is as follows:


MAMBAXIE-MC0:TextBoxes mambaxie$ python convert.py

/Users/mambaxie/anaconda2/lib/python2.7/site-packages/coremltools/proto

[libprotobuf ERROR /git/coreml/deps/protobuf/src/google/protobuf/text_format.cc:298] Error parsing text-format caffe.NetParameter: 758:14: Message type "caffe.LayerParameter" has no field named "norm_param".

Traceback (most recent call last):

File "convert.py", line 8, in <module>

image_input_names='data'

File "/Users/mambaxie/anaconda2/lib/python2.7/site-packages/coremltools/converters/caffe/_caffe_converter.py", line 142, in convert

predicted_feature_name)

File "/Users/mambaxie/anaconda2/lib/python2.7/site-packages/coremltools/converters/caffe/_caffe_converter.py", line 187, in _export

predicted_feature_name

RuntimeError: Unable to load caffe network Prototxt file: deploy.prototxt


How can I fix it?

Replies

Hi mambaxie,

Thanks for your post! Could you share the model files so that we can run a diagnosis?

Hi mambaxie,


Are you able to load the prototxt and caffemodel files using the official BVLC Caffe installation? It seems the prototxt has a layer called "norm_param", but this is not part of Caffe. It might be that you are using a protoxt file that was generated on a fork of Caffe.

Core ML caffeconverter only sypports BVLC version of caffe models.

For models based on forks of Caffe, if they can be expressed using layers supported by Core ML, you can produce custom built mlmodels. Kindly look into the neural network builder functionality in coremltools.

Hi allenlin, I want to convert CTPN's caffe model to mlmodel, but how does CTPN have a custom layer and how do I convert it?

CTPN's github : https://github.com/tianzhi0549/CTPN