Stanislav Jirák
Stanislav Jirák

Reputation: 485

module 'Tensorflow' has no atributte

I'm getting these weird errors in Google Colab when using TensorFlow, like:

AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'

or

module 'tensorflow' has no attribute 'placeholder'

Help would appreciated.

Upvotes: 0

Views: 4046

Answers (3)

Debashis Sahoo
Debashis Sahoo

Reputation: 5912

To resolve version issues in TensorFlow, it's a good idea to use this below technique to import v1 (version 1 or TensorFlow 1. x) and we also can disable the TensorFlow 2. x behaviors.

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

Here you don't have to uninstall or re-install anything.

Upvotes: 0

Anwarvic
Anwarvic

Reputation: 12992

This problem happens because the current version installed on GoogleColab is tensorflow 2.2.0. And apparently, the code you're using assumes that tensorflow 1.x is installed.

So, you can fix this issue using two ways:

  • Either downgrading your tensorflow to 1.x like so:

     !pip install tensorflow==1.15
    
  • Or you can use the methods provided in tensorflow.comat.v1 package like tf.compat.v1.reset_default_graph instead of tf.reset_default_graph and tf.compat.v1.placeholder instead of tf.placeholder.

I really encourage the first solution as the second solution will require a lot of changes that can lead to mistakes.

I really used in

Upvotes: 2

Varun Rajkumar
Varun Rajkumar

Reputation: 418

Try using tf.compat.v1.placeholder and tf.compat.v1.reset_default_graph. If you have any more attribute errors, you can look at the tensorflow documentation.

Upvotes: 1

Related Questions