TheQuantumMan
TheQuantumMan

Reputation: 265

I get error: module 'tensorflow.keras.layers' has no attribute 'Normalization'

I use

layers.Normalization()

in Keras, in keras.Sequential When I try to run it, I get the following error:

module 'tensorflow.keras.layers' has no attribute 'Normalization'

I've seen the command layers.Normalization() being used in many codes, so I don't know what's wrong. Did something change?

Upvotes: 9

Views: 22068

Answers (2)

Ramesh Kumar
Ramesh Kumar

Reputation: 181

One reason can be that you are using the tensorflow version older then the required to use that layer. There are two ways to get around this problem.

  1. Upgrade tensorflow as discussed above.
  2. Or you can add the layer as follows:
tf.keras.layers.experimental.preprocessing.Normalization

Regards

Upvotes: 16

politecat314
politecat314

Reputation: 141

Check the version of TensorFlow you have:

import tensorflow as tf
print(tf.__version__)

tf.keras.layers.Normalization is an attribute in TensorFlow v2.6.0, so might not work on earlier versions: https://www.tensorflow.org/api_docs/python/tf/keras/layers/Normalization

If you have an earlier version, you can upgrade using

pip install --upgrade tensorflow

Upvotes: 5

Related Questions