TypeError: 'InputLayer' object is not iterable with CoreMLTools

ぐ巨炮叔叔 提交于 2021-01-07 02:32:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!