TensorFlow: input shape is incompatible

  • TensorFlow
  • Keras

You may see

ValueError: Input 0 of layer
is incompatible with the layer: expected shape=

Why it happens

  • The picture isn't the size used in training.
  • The batch dimension is missing.
  • Pixels weren't scaled the same way.

How to fix it

  1. Resize to the training size.
  2. Add a batch: np.expand_dims(img, 0).
  3. Scale exactly as in training (for example divide by 255).

It worked if: model.predict gives numbers.

From the official documentation. Keras' usual wording; TensorFlow isn't installed here, so it was not reproduced. Sources: Keras documentation.

Didn't help? Search another error or ask us.