Skip to content Skip to sidebar Skip to footer

Why Is Keras Complaining About Incompatible Input Shape In This Case?

I have trained a Keras-based autoencoder model with the following input layer: depth = 1 width = height = 100 input_shape = (height, width, depth) inputs = Input(shape=input_shape)

Solution 1:

These simple lines of code generate the error

X = np.random.uniform(0,1, (100,100,1))

inp = Input((100,100,1))
out = Dense(1)(Flatten()(inp))
model = Model(inp, out)

model.predict(X)

This is because your Keras model expects data in this format (n_sample, 100, 100, 1)

A simple reshape when you predict a single image does the trick

model.predict(X.reshape(1,100,100,1))

Post a Comment for "Why Is Keras Complaining About Incompatible Input Shape In This Case?"