'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.
Solution 1:[1]
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
tensorflowto1.xlike so:!pip install tensorflow==1.15Or you can use the methods provided in
tensorflow.comat.v1package liketf.compat.v1.reset_default_graphinstead oftf.reset_default_graphandtf.compat.v1.placeholderinstead oftf.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
Solution 2:[2]
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.
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anwarvic |
| Solution 2 | Varun Rajkumar |
| Solution 3 | debaonline4u |
