简体   繁体   中英

How can I solve the error “Cannot import name 'x' ”?

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')

确保您要导入的名称在模块coremltools中。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM