Can't convert Keras model to Coreml

I have tried various ways to convert my Keras model to core ml using core ml tools, but it gives me this error.

Keras layer '<class 'tensorflow.python.keras.engine.input_layer.InputLayer'>' not supported.



This is how my model looks.

img_input = layers.Input(shape=(224, 224, 3))


seed = 230

numpy.random.seed(seed)



x = layers.Conv2D(16, 3, activation='relu')(img_input)

x = layers.MaxPooling2D(2)(x)

x = layers.Conv2D(32, 3, activation='relu')(x)

x = layers.MaxPooling2D(2)(x)

x = layers.Flatten()(x)

x = layers.Dense(128, activation='relu')(x)

x = layers.Dropout(0.4)(x)


output = layers.Dense(3, activation='softmax')(x)



model = Model(img_input, output)

model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])


Accepted Reply

I would try using standalone Keras (pip install keras). There's nothing in your model per se that Core ML can't handle, but the converter tool currently doesn't support tf.keras, only the Keras that is not built into TensorFlow.

Replies

That's because you're using the Keras that is built into TensorFlow, not the standalone Keras.


See also these issues: https : //github.com/apple/coremltools/issues/446

so what and where should I change to that in my code ??

I would try using standalone Keras (pip install keras). There's nothing in your model per se that Core ML can't handle, but the converter tool currently doesn't support tf.keras, only the Keras that is not built into TensorFlow.