I was able to successfully save the MobileNet NIMA model as a coreML model however the input is not what I was expecting. It shows the input as MultiArray instead of an Image
base_model = MobileNet((None, None, 3), alpha=1, include_top=False, pooling='avg', weights=None)
x = Dropout(0.75)(base_model.output)
x = Dense(10, activation='softmax')(x)
model = Model(base_model.input, x)
model.load_weights('weights/mobilenet_weights.h5')
coreml_model = coremltools.converters.keras.convert(model)
coreml_model.save("mobilenet_nima2.mlmodel")
CoreML metaData

Ideally what the input and output should resemble:

I also tried converting the model by passing in an image_input_names parameter
coreml_model = coremltools.converters.keras.convert(model, image_input_names='img', input_names='img')
but I received an unpack error from the coreML builder tools
/coremltools/models/neural_network/builder.py", line 2547, in set_pre_processing_parameters
channels, height, width = array_shape
ValueError: need more than 1 value to unpack
Code where the error originates
https://github.com/apple/coremltools/blob/master/coremltools/models/neural_network.py
# Add image inputs
for input_ in spec.description.input:
if input_.name in image_input_names:
if input_.type.WhichOneof('Type') == 'multiArrayType':
array_shape = tuple(input_.type.multiArrayType.shape)
channels, height, width = array_shape
Any idea why the keras model is converting to a CoreML model with input MultiArray type instead of an image?
There have been MobileNet models that have been successfully converted to a CoreML model with image as an input e.g. https://github.com/hollance/MobileNet-CoreML
This seems related to issue #189
Check the the Keras model has the input shapes fully defined.
Thanks @aseemw !
For future reference. I was able to generate the coreml model with the image input by modifying how I generated the keras model:
base_model = MobileNet((None, None, 3), alpha=1, include_top=False, pooling='avg', weights=None)
became
base_model = MobileNet((224, 224, 3), alpha=1, include_top=False, pooling='avg', weights=None)
then
coreml_model = coremltools.converters.keras.convert(model, image_input_names='img', input_names='img')
Most helpful comment
This seems related to issue #189
Check the the Keras model has the input shapes fully defined.