def convert_keras_to_mlmodel(keras_url, mlmodel_url):
from keras.models import load_model
keras_model = load_model(keras_url)
from coremltools.converters import keras as keras_converter
class_labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
mlmodel = keras_converter.convert(keras_model, input_names=['image'],
output_names=['digitProbabilities'],
class_labels=class_labels,
predicted_feature_name='digit')
mlmodel.save(mlmodel_url)
coreml_model_path = './MNISTDigitClassifier.mlmodel' convert_keras_to_mlmodel(keras_model_path , coreml_model_path)
Getting Below error:
ImportError Traceback (most recent call last) Cell In[10], line 19 16 mlmodel.save(mlmodel_url) 18 coreml_model_path = './MNISTDigitClassifier.mlmodel' ---> 19 convert_keras_to_mlmodel(keras_model_path , coreml_model_path)
Cell In[10], line 9, in convert_keras_to_mlmodel(keras_url, mlmodel_url) 6 from keras.models import load_model 7 keras_model = load_model(keras_url) ----> 9 from coremltools.converters import keras as keras_converter 10 class_labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] 11 mlmodel = keras_converter.convert(keras_model, input_names=['image'], 12 output_names=['digitProbabilities'], 13 class_labels=class_labels, 14 predicted_feature_name='digit')
ImportError: cannot import name 'keras' from 'coremltools.converters' (/Users/anaamrasool/new-tensorflow-env/env/lib/python3.8/site-packages/coremltools/converters/init.py)