Keras model conversion: image_input_names not working

I am trying to perform a classification task. I am using `keras` and my model starts with an input layer as shown below:


data = Input(shape=(height, width, depth))


Once training is complete, I have the following two lines to create the `CoreML` model:


coreml_model = coremltools.converters.keras.convert(model, input_names='data', image_input_names='data', is_bgr=True)
coreml_model.save('my_model.mlmodel')


However, when I check this file, I see Input as `MultiArray` instead of `Image <BGR, 32, 32>` or `CVPixelBuffer`. How can I make sure that my input is an image?

Replies

Is 'data' the name of the keras input layer?

The input needs to be in shape (depth, height, width) in order to be converted. Here's the code:

array_shape = tuple(input_.type.multiArrayType.shape)
channels, height, width = array_shape


Also make sure channels is either 1 or 3.

coreml_model_new = coremltools.converters.keras.convert(final_model,input_names='image',
                                                        output_names='probs',image_input_names='image',
                                                        class_labels='classes.txt',
                                                        predicted_feature_name='class',image_scale=1./255)


I get the error in this line when I try to transform it to 'image'.

array_shape = tuple(input_.type.multiArrayType.shape)
channels, height, width = array_shape
ValueError: need more than 1 value to unpack


I'm not sure what happened but it worked with a keras model I used with an earlier version of coremltools.