Getting attribute error when using AUTOTUNE in Tensorflow?

Viewed 9361

I am using AUTOTUNE for audio processing.

import tensorflow as tf
AUTOTUNE = tf.data.AUTOTUNE

But i am getting attribute error which said "module 'tensorflow._api.v2.data' has no attribute 'AUTOTUNE'". Tensorflow version is 2.3.0. How to solve this?

4 Answers

According to the TensorFlow 2.3 documentation, AUTOTUNE lies under the tensorflow.data.experimental namespace. So using

AUTOTUNE = tf.data.experimental.AUTOTUNE

should avoid this error.

With TF 2.3, Autotune was experimental and was in nightly build but in TF 2.5, it is in packages. We can do this if we want to train the model in TF 2.5 or TF 2.3.

try:
    AUTOTUNE = tf.data.AUTOTUNE     
except:
    AUTOTUNE = tf.data.experimental.AUTOTUNE 
  

At least TF 2.4 you should install.

Upgrade your TensorFlow using following comment

pip install --upgrade tensorflow
Related