Posts

Post not yet marked as solved
1 Replies
956 Views
I am working on the neural network classifier provided on the coremltools.readme.io in the updatable->neural network section(https://coremltools.readme.io/docs/updatable-neural-network-classifier-on-mnist-dataset). I am using the same code but I get an error saying that the coremltools.converters.keras.convert does not exist. But this I know can be coreml version issue. Right know I am using coremltools version 6.2. I converted this model to mlmodel with .convert only. It got converted successfully. But I face an error in the make_updatable function saying the loss layer must be softmax output. Even the coremlt package API reference there I found its because the layer name is softmaxND but it should be softmax. Now the problem is when I convert the model from Keras sequential model to coreml model. the layer name and type change. And the softmax changes to softmaxND. Does anyone faced this issue? if I execute this builder.inspect_layers(last=4) I get this output [Id: 32], Name: sequential/dense_1/Softmax (Type: softmaxND) Updatable: False Input blobs: ['sequential/dense_1/MatMul'] Output blobs: ['Identity'] [Id: 31], Name: sequential/dense_1/MatMul (Type: batchedMatmul) Updatable: False Input blobs: ['sequential/dense/Relu'] Output blobs: ['sequential/dense_1/MatMul'] [Id: 30], Name: sequential/dense/Relu (Type: activation) Updatable: False Input blobs: ['sequential/dense/MatMul'] Output blobs: ['sequential/dense/Relu'] In the make_updatable function when I execute builder.set_categorical_cross_entropy_loss(name='lossLayer', input='Identity') I get this error ValueError: Categorical Cross Entropy loss layer input (Identity) must be a softmax layer output.
Posted Last updated
.
Post not yet marked as solved
0 Replies
470 Views
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)
Posted Last updated
.