简体   繁体   English

加载集合 keras model 给出 ValueError: Invalid input_shape argument (None, 224, 224, 3): Z20F35E630DAF44DBFA4C3F608F5399D8C 有输入

[英]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.

相关问题 Tensorflow / Keras ValueError:层“模型”的输入 0 与层不兼容:预期形状=(无,224,224,3),发现形状=(32,224,3) - Tensorflow / Keras ValueError: Input 0 of layer "model" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(32, 224, 3) ValueError: Input 0 is incompatible with layer similar_model: expected shape=(None, 224, 224, 3), found shape=(None, None, 224, 224, 3) - ValueError: Input 0 is incompatible with layer similarity_model: expected shape=(None, 224, 224, 3), found shape=(None, None, 224, 224, 3) 拟合我的模型时出现 ValueError。 (ValueError:无法将输入数组从形状(224,224,3)广播到形状(224,224,3,3)) - ValueError when fitting my model. (ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224,3,3)) ValueError: 图层“model_1”的输入 0 与图层不兼容:预期形状=(None, 224, 224, 3),发现形状=(None, 290, 290, 3) - ValueError: Input 0 of layer "model_1" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(None, 290, 290, 3) ValueError:层“model_10”的输入 0 与层不兼容:预期形状 =(None, 244, 244, 3),找到的形状 =(None, 224, 224, 3) - ValueError: Input 0 of layer "model_10" is incompatible with the layer: expected shape=(None, 244, 244, 3), found shape=(None, 224, 224, 3) ValueError:无法为张量为'(?,224,224,3)'的张量'Placeholder_3:0'输入形状(224,224,3)的值 - ValueError: Cannot feed value of shape (224, 224, 3) for Tensor 'Placeholder_3:0', which has shape '(?, 224, 224, 3)' ValueError: Input 0 is in compatible with layer vggface_resnet50: expected shape=(None, 224, 224, 3), found shape=(None, 1, 224, 224, 3) - ValueError: Input 0 is incompatible with layer vggface_resnet50: expected shape=(None, 224, 224, 3), found shape=(None, 1, 224, 224, 3) 我收到错误,例如“图层“model_5”的输入 1 与图层不兼容:预期形状 =(无,224、224、3),找到形状 =(无,5) - I am getting error like "Input 1 of layer "model_5" is incompatible with the layer: expected shape=(None, 224, 224, 3), found shape=(None, 5) Keras - ValueError:Sequential模型中的第一层必须得到`input_shape`或`batch_input_shape`参数 - Keras - ValueError: The first layer in a Sequential model must get an `input_shape` or `batch_input_shape` argument ValueError:无法将输入数组从形状 (224,224,3) 广播到形状 (224,224) - ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM