简体   繁体   中英

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. 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:

ValueError: Invalid input_shape argument (None, 224, 224, 3): model has 0 tensor inputs. Full trace: 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

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. I would still like to know why that happens.

If you rename one of your layers, it could be problem. Stop renaming.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question 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 similarity_model: expected shape=(None, 224, 224, 3), found shape=(None, None, 224, 224, 3) ValueError when fitting my model. (ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224,3,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: Input 0 of layer "model_10" is incompatible with the layer: expected shape=(None, 244, 244, 3), found shape=(None, 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 incompatible with layer vggface_resnet50: expected shape=(None, 224, 224, 3), found shape=(None, 1, 224, 224, 3) 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: The first layer in a Sequential model must get an `input_shape` or `batch_input_shape` argument ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM