Coremltools: Cannot import name relu6

Created on 27 Oct 2018  路  5Comments  路  Source: apple/coremltools

traceback (after attempting to convert custom MobileNet model)

Traceback (most recent call last):
  File "coremlconverte2r.py", line 42, in <module>
    class_labels=class_labels)
  File "/Users/user147784/Library/Python/2.7/lib/python/site-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
    custom_conversion_functions=custom_conversion_functions)
  File "/Users/user147784/Library/Python/2.7/lib/python/site-packages/coremltools/converters/keras/_keras_converter.py", line 534, in convertToSpec
    from . import _keras2_converter
  File "/Users/user147784/Library/Python/2.7/lib/python/site-packages/coremltools/converters/keras/_keras2_converter.py", line 14, in <module>
    from . import _layers2
  File "/Users/user147784/Library/Python/2.7/lib/python/site-packages/coremltools/converters/keras/_layers2.py", line 10, in <module>
    from keras_applications.mobilenet import relu6
ImportError: cannot import name relu6

Tried the following solution

from keras.utils.generic_utils import CustomObjectScope
with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):

Still received error

WARNING:root:Keras version 2.2.4 detected. Last version known to be fully compatible of Keras is 2.1.6 .
WARNING:root:TensorFlow version 1.11.0 detected. Last version known to be fully compatible is 1.5.0 .
Traceback (most recent call last):
  File "coremlconverte2r.py", line 12, in <module>
    with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):
AttributeError: 'module' object has no attribute 'relu6'

Have not even the slightest of idea whats causing this.

All 5 comments

Whats the version of Keras installed on your system?
Can you build from top of master and try again?
This error should be resolved after PR #278 went in.

Latest version of keras (2.2.4)
Currently on a virtual mac environment so it has python 2.7.10 and 3.7

Trying to build from master, not familiar with Cmake

Would correct statement be:
cmake . DPYTHON=$(python)

Just execute these commands:

git clone https://github.com/apple/coremltools.git
cd coremltools
cmake . -DPYTHON=$(which python) -DPYTHON_CONFIG=$(which python-config)
make
pip install -e .

Thanks for the help.

for anyone else this will do the trick also
pip install -U https://github.com/apple/coremltools/archive/master.zip --user

@zantism Using pip install would omit the native libraries used by Core ML. Recompiling from source is a better option.

Also take note of #295 (missing MLFeatureTypeSequence symbol) when building from source.

Was this page helpful?
0 / 5 - 0 ratings