问题
I'm trying to convert a VGG model to coremltools. When I run the following code to convert the model:
with CustomObjectScope({'relu6': keras.layers.ReLU,'DepthwiseConv2D': keras.layers.DepthwiseConv2D}):
from keras.models import load_model
import coremltools
model_directory = 'KerasModels/VGG-7-3-20_13categories.h5'
keras_model = load_model(model_directory)
input_layer = InputLayer(input_shape=(224, 224, 3), name="input_1")
# Save and convert :
keras_model.layers[0] = input_layer
keras_model.save(model_directory)
print("Changed2")
your_model = coremltools.converters.keras.convert(model_directory, input_names=['image'], output_names=['output'], image_input_names='image')
your_model.save('RecycleNet.mlmodel')
I get the following error:
TypeError: 'InputLayer' object is not iterable
How should I go about converting this model to coremltools? Thanks
回答1:
I fixed this error by switching from using:
coremltools.converters.keras
to:
coremltools.converters.tensorflow
回答2:
This line of code solved for me:
coremlModel = coremltools.convert(model)
instead of using this:
coremlModel = coremltools.converters.keras.convert(model)
来源:https://stackoverflow.com/questions/62719352/typeerror-inputlayer-object-is-not-iterable-with-coremltools