ValueError: Shape must be rank 1 but is rank 4

I'm using Keras 2.2.4 and just a simple code for BatchNormalization throws this error

ValueError: Shape must be rank 1 but is rank 4 for 'batch_normalization_1/cond/FusedBatchNorm' (op: 'FusedBatchNorm') with input shapes

The back-end is Tensorflow. Here is the code I'm running

from keras.layers import BatchNormalization, Input
x = Input(shape=(1, 32, 32))
BatchNormalization(axis=1)(x)

What's wrong with this?

tensorflowkerasbatch-normalization
3 votesJW234.00
1 Answers
JO220.00
3

Keras 2.1.6 works for me. You gonna need to downgrade your Keras' version.

Just run these commands

pip uninstall keras
pip install keras==2.1.6

They've got a bug in Keras 2.2.* and we don't know if it's fixed in new versions or not.

Reply
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?