Search code examples
caffecoremlcoremltools

Fail to convert Caffe model to Core ML model


When I try to convert a model from Caffe to Core ML model with coremltools, I get the following:

================= Starting Conversion from Caffe to CoreML ======================
Layer 0: Type: 'Data', Name: 'data'. Output(s): 'data', 'label'.
WARNING: Skipping Data Layer 'data' of type 'Data'. It is recommended to use Input layer for deployment.
Layer 1: Type: 'Split', Name: 'label_data_1_split'. Input(s): 'label'. Output(s): 'label_data_1_split_0', 'label_data_1_split_1'.
Layer 2: Type: 'Convolution', Name: 'conv1'. Input(s): 'data'. Output(s): 'conv1'.
Layer 3: Type: 'Slice', Name: 'slice1'. Input(s): 'conv1'. Output(s): 'slice1_1', 'slice1_2'.
Layer 4: Type: 'Eltwise', Name: 'etlwise1'. Input(s): 'slice1_1', 'slice1_2'. Output(s): 'eltwise1'.
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    coreml_model = coremltools.converters.caffe.convert('_iter_3560000.caffemodel')
  File "/Users/zfh/Desktop/face_verification_experiment/model/python27/lib/python2.7/site-packages/coremltools/converters/caffe/_caffe_converter.py", line 142, in convert
    predicted_feature_name)
  File "/Users/zfh/Desktop/face_verification_experiment/model/python27/lib/python2.7/site-packages/coremltools/converters/caffe/_caffe_converter.py", line 187, in _export
    predicted_feature_name
RuntimeError: Unsupported option 'Max' for the parameter 'operation' in layer 'etlwise1' of type 'Elementwise' during caffe conversion.

This is the code I am using:

import coremltools
coreml_model = coremltools.converters.caffe.convert(('_iter_3560000.caffemodel', 'LCNN_deploy.prototxt'))

coreml_model.save('_iter_3560000.mlmodel')

Any ideas what the problem is? Thank you very much!


Solution

  • As the error message says, the problem is that the Max operation in an Eltwise layer is not supported by the coremltools. Core ML only supports a limited number of layers.

    However... it seems like maybe you're trying to convert the .prototxt that was used for training (even though the filename is LCNN_deploy.prototxt). Are you sure this is the correct deploy.prototxt?