Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoreML model input type is MultiArray instead of Image #34

Closed
keithZumper opened this issue Jun 26, 2018 · 2 comments
Closed

CoreML model input type is MultiArray instead of Image #34

keithZumper opened this issue Jun 26, 2018 · 2 comments

Comments

@keithZumper
Copy link

keithZumper commented Jun 26, 2018

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
screen shot 2018-06-25 at 7 17 43 pm

Ideally what the input and output should resemble:
screen shot 2018-06-25 at 7 17 40 pm

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

@titu1994
Copy link
Owner

Instead of using None, None, 3 as the input shape, use a static size such as 224.

@keithZumper
Copy link
Author

Worked! Thanks @titu1994

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants