apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.43k stars 641 forks source link

Unable to convert Keras MobileNetV2 model #1199

Closed Ludotrico closed 2 years ago

Ludotrico commented 3 years ago

I am unable to convert a simple Keras MobileNetV2 model. Here is the code:

baseModel = MobileNetV2(
input_shape=(224, 224, 3),
include_top=False, weights='imagenet',
)
baseModel.trainable = False

model = Sequential([
  baseModel,
  Dense(5, activation='softmax')
  ])

output_labels = ['0', '1', '2', '3', '4']
coreModel = coremltools.converters.keras.convert(model,
          input_names=['image'],
          output_names=['output'],
          class_labels=output_labels,
          image_input_names='image')

coreModel.save('coreModel.mlmodel')

Here is the bug, it is triggered on the keras.convert function:

File "convert.py", line 13 image_input_names='image') File "/Users/ludovico/Documents/Documents2.0/School/Glaucoma/code/env/lib/python3.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 828, in convert use_float_arraytype=use_float_arraytype, File "/Users/ludovico/Documents/Documents2.0/School/Glaucoma/code/env/lib/python3.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 605, in _convert_to_spec use_float_arraytype=use_float_arraytype, File "/Users/ludovico/Documents/Documents2.0/School/Glaucoma/code/env/lib/python3.7/site-packages/coremltools/converters/keras/_keras2_converter.py", line 361, in _convert graph.build() File "/Users/ludovico/Documents/Documents2.0/School/Glaucoma/code/env/lib/python3.7/site-packages/coremltools/converters/keras/_topology2.py", line 703, in build for pred in node.inbound_layers: TypeError: 'InputLayer' object is not iterable

TobyRoseman commented 3 years ago

What version of keras are you using?

TobyRoseman commented 2 years ago

Since we have not received the requested information, I'm going to close this issue.