Error trying to use Coremltools

I installed coremltools and when I try to import coremltools into python I am getting this error:

Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import coremltools
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/coremltools/__init__.py", line 29, in <module>
    import converters
  File "/Library/Python/2.7/site-packages/coremltools/converters/__init__.py", line 10, in <module>
    import keras
  File "/Library/Python/2.7/site-packages/coremltools/converters/keras/__init__.py", line 15, in <module>
    from ._keras_converter import convert
  File "/Library/Python/2.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 17, in <module>
    import _topology
  File "/Library/Python/2.7/site-packages/coremltools/converters/keras/_topology.py", line 24, in <module>
    _keras.layers.advanced_activations.ParametricSoftplus,
AttributeError: 'module' object has no attribute 'ParametricSoftplus'


Keras info:

>>> import keras
>>> print keras.__version__
2.0.4
>>> print keras.__path__
['/Library/Python/2.7/site-packages/keras']


Any ideas how to get coremltools working?

Accepted Reply

Never mind - coremltools only supports Keras 1.2.2. Installed it with:


sudo pip install keras==1.2.2


And seems to work now. Bummer though because the model I wanted to convert is Keras 2...

Replies

Never mind - coremltools only supports Keras 1.2.2. Installed it with:


sudo pip install keras==1.2.2


And seems to work now. Bummer though because the model I wanted to convert is Keras 2...

Hi.


How to install coremltools at all? Command `pip install -U coremltools` described here https://pypi.python.org/pypi/coremltools produses output:


Collecting coremltools
  Could not find a version that satisfies the requirement coremltools (from versions: )
No matching distribution found for coremltools


I have no idea what does that mean.


Regards,

Valeriy

keras 1.2.2 is already installed but I still get the same error:


$ python
Python 3.5.2 | packaged by conda-forge | (default, Jan 20 2017, 20:58:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
>>> print(keras.__version__)
1.2.2

pip install -U coremltools
Collecting coremltools
  Could not find a version that satisfies the requirement coremltools (from versions: )
No matching distribution found for coremltools


Any ideas how to solve that?

The reason why you have this problem is because you need to be running Python 2.7.x to be able to install coremltools


check which Python you are running by running: python --version


if you are running Python 3.6.x for instance, you will need to create a new virtual environment with Python 2.7.x


I like "Anaconda" as the tool to manage the environments (check out https://docs.continuum.io/anaconda/install/ )

I have the same problem - trying to convert a Keras 2 model to coremltools.


Does anyone know if this has been resolved, or ... is there a tool I can use to convert a Keras 2 model to 1.2.2?


Cheers

Keras 2 support is supposed to be in place, but I'm getting this error too: AttributeError: 'module' object has no attribute 'convert'

What's up? Python 2.7.13, keras 2.0.6

I rolled back to 2.0.4, just as a test, but same error...

In case anyone hits the same problem and winds up here, you need to use the Tensorflow backend (at least for now).

coremltools works with keras 2.0.4 and tensorflow 1.1.1

if you want to be able to use coreml, simply proceed as follow :

create a new virtualenv with python 2.7 as your default interpreter

then install keras 2.0.4, numpy, coremltools using the pip command

It should now works

let me know if you still have some problems