简体   繁体   中英

Keras error: “BatchNormalization Shape must be rank 1 but is rank 4 for batch_normalization”

I have a Keras functional model (Neural network with convolutional layers) which works fine with tensorflow. I can run it and I can fit it.

However, the model cannot be built when tensorflow gpu is used.

This is the line of the code when building the model which throws the error.

x = BatchNormalization(axis=1)(x)

And the error message is " BatchNormalization Shape must be rank 1 but is rank 4 for batch_normalization ".

It seems to me that it is a bug in Keras. If so, if there is a fix, how can I install this particular fix into Windows/Anaconda environment?

Keras version is 2.2.0 and tensorflow gpu 1.8.0

Any idea?

Thanks in advance to everyone.

It seems to me that there is a tensorflow-gpu - keras version incompatibility in your machine.

Try keras 2.1.6

pip uninstall keras
pip install -I keras==2.1.6

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM