coremltool converting Caffe model: "RuntimeError: Unable to load Caffe converter library."

I'm trying to convert a caffemodel file with the coremltools, and get the following:


>>> import coremltools
>>> coreml_model = coremltools.converters.caffe.convert(('model.caffemodel','deploy.prototxt','mean.binaryproto'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/coremltools/converters/caffe/_caffe_converter.py", line 130, in convert
    predicted_feature_name)
  File "/Library/Python/2.7/site-packages/coremltools/converters/caffe/_caffe_converter.py", line 144, in _export
    raise RuntimeError('Unable to load Caffe converter library.')
RuntimeError: Unable to load Caffe converter library.


I installed coremltools with pip:

sudo pip install --ignore-installed six coremltools


I was getting pip errors with the six package, hence the extra argument. The documentation doesn't say I need an additional packages for caffe. Even the example code in the documentation:

mport coremltools 
# Convert a caffe model to a classifier in Core ML
coreml_model = coremltools.converters.caffe.convert(('bvlc_alexnet.caffemodel', 'deploy.prototxt'), predicted_feature_name='class_labels.txt' )


failes to run with this error.

Accepted Reply

You are using the wrong version of Python (and possibly Keras).


It is best if you create a virtualenv and install the dependencies in there:


virtualenv -p /usr/bin/python2.7 env
source env/bin/activate
pip install tensorflow
pip install keras==1.2.2
pip install coremltools


Notice that I'm specifying "-p /usr/bin/python2.7" so that the virtualenv uses the system Python, not whatever other Python you have installed.

Replies

My installation sudo -H pip install --no-cache-dir six==1.4.1

Part of the issue was my install command. Just reinstalled with:

pip install -U coremltools

as listed in the documentation. Now I get the following:

Python 2.7.13 (default, Apr  4 2017, 08:47:57)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import coremltools
>>> coreml_model = coremltools.coverters.caffe.convert(('bclc_alexnet.caffemodel', 'deploy.prototxt'), predicted_feature_name='class_labels.txt')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'coverters'
>>> coreml_model = coremltools.converters.caffe.convert(('bclc_alexnet.caffemodel', 'deploy.prototxt'), predicted_feature_name='class_labels.txt')
Fatal Python error: PyThreadState_Get: no current thread
[1]    97245 abort      python


So now it is crashing Python, but the original error is gone

You are using the wrong version of Python (and possibly Keras).


It is best if you create a virtualenv and install the dependencies in there:


virtualenv -p /usr/bin/python2.7 env
source env/bin/activate
pip install tensorflow
pip install keras==1.2.2
pip install coremltools


Notice that I'm specifying "-p /usr/bin/python2.7" so that the virtualenv uses the system Python, not whatever other Python you have installed.

Thanks, this solved the issue!