Skip to content Skip to sidebar Skip to footer

How To Fix ''valueerror: Input 0 Is Incompatible With Layer Flatten: Expected Min_ndim=3, Found Ndim=2" Error When Loading Model

I'm trying to save and load my keras model. It trains, evaluates, and saves fine (using .h5 to save model) but when I try to load the model I get the following error: ValueError:

Solution 1:

you can try to save only the weights of your model, then re-create it using exactly the same code, and loading only the weights. so change

model.save

to

model.save_weights('my_model.h5')

Then when you want to load your model, first, you re-create your model:

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
self.addLayer(model,145,6)
model.add(tf.keras.layers.Dense(1))

and finally load the weights:

model.load_weights('my_model.h5')

This worked for me. Also, you could add an Input layer, together with the explicit input_shape in your model.

Post a Comment for "How To Fix ''valueerror: Input 0 Is Incompatible With Layer Flatten: Expected Min_ndim=3, Found Ndim=2" Error When Loading Model"