[英]Loading ensemble keras model gives ValueError: Invalid input_shape argument (None, 224, 224, 3): model has 0 tensor inputs
My model is an ensemble of 2 different keras models, the models are connected to same input layer and have 2 output layers when combined.我的 model 是 2 个不同的 keras 模型的集合,这些模型连接到相同的输入层,并在组合时具有 2 个 output 层。 Both models are pretrained and I am trying to create a parallel architecture.
这两个模型都是预训练的,我正在尝试创建一个并行架构。 My architecture is: `
我的架构是:`
model_input = Input(shape=(224,224,3), name="model_input")
gender_model_copy.layers.pop(0)
color_model_copy.layers.pop(0)
color_model_ens1 = color_model_copy(model_input)
gender_model_ens1 = gender_model_copy(model_input)
model_f = Model(input=[model_input], output=[color_model_ens1,gender_model_ens1])
model_f.save('path')
` `
The model gets compiled and I can make predictions as well but when I save it and try to reload it I get, I get: model 已编译,我也可以进行预测,但是当我保存它并尝试重新加载它时,我得到了:
ValueError: Invalid input_shape argument (None, 224, 224, 3): model has 0 tensor inputs.
Full trace: Github gist link .完整跟踪: Github gist link 。
I have a custom layer which I am adding by using custom_objects={'Scale':Scale()}
argument in keras.models.load_model
My keras version is 2.2.5 and tensorflow version is 1.15我有一个自定义层,我通过在 keras.models.load_model 中使用
custom_objects={'Scale':Scale()}
参数添加我的keras.models.load_model
版本是 2.2.5 和 Z2C39BC19B761AC36DC046245D1 版本。
EDIT : I realized that the problem was that I was making layers untrainable by layer.trainable=False
, without doing that I was able to load the models without the error.编辑:我意识到问题是我通过
layer.trainable=False
使图层无法训练,如果不这样做,我就能够加载模型而不会出错。 I would still like to know why that happens.我仍然想知道为什么会这样。
If you rename one of your layers, it could be problem.如果您重命名其中一个图层,则可能会出现问题。 Stop renaming.
别改名了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.