0
votes

I'm trying to convert Keras to a Core ML model but I'm stuck when converting the Python file into a mlmodel.

I'm getting errors when importing submodules of 'coremltools'.

The error that I'm getting is: "python recog.py Traceback (most recent call last): File "recog.py", line 3, in from coremltools import convert ImportError: cannot import name 'convert' "

I tried to import the submodules in a different way but nothing worked for me.

I hope anyone can help me!

You can see the Python code, in the sample below:

import coremltools
from coremltools import converters
from coremltools import convert

coreml_model = coremltools.converters.keras.convert('model.h5', input_names='data', image_input_names='data', is_bgr=True, output_names='species')
coreml_model.save('model.mlmodel')
2
There is no convert module, package or name in the coremltools package (See github.com/apple/coremltools/tree/v0.8/coremltools) For importing the keras converter, write this to import the keras package: from coremltools.converters import keras. Then use as keras.convert(...) - Oluwafemi Sule

2 Answers

0
votes

Make sure the name you are trying to import is in the module coremltools.

0
votes

In the file, coremtools.py double check if the name is same I.e. convert. Check the location of the coremtools.py file, is it in the main folder of python where python.exe exists?