AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'
Solution 1
You normally import tensorflow
by writing,
import tensorflow as tf
It's possible that you have named a file in your project tensorflow.py
and the import
statement is importing from this file.
Alternatively, you can try this,
from tensorflow.python.framework import ops
ops.reset_default_graph()
Solution 2
This function is deprecated.
Use tf.compat.v1.reset_default_graph()
instead.
Update This is not the only function to be out of date. Check out this answer for release notes and a conversion script.
Solution 3
I have tried and successfully removed the attribute error
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import MaxPool2D
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dense
classifier = Sequential()
Solution 4
Actually, this answer will resolve all TF 1.x related issues.
Get TF 1.x like behaviour in TF 2.0 by using this:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
Solution 5
Change:
import keras.<something>.<something>
to:
import tensorflow.keras.<something>.<something>
Where 'something' is the module you want to import
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I have installed tensorflow version r0.11.
In my file name
cartpole.py
I have importedtensorflow
:import tensorflow as tf
and use it:
tf.reset_default_graph()
Trying to run my project in PyCharm I get this error:
in <module> tf.reset_default_graph() AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'
How can I fix this error?
-
Admin over 7 yearsI tried this your tip. But this occured: Command "python setup.py egg_info" failed with error code 1 I've used: pip install --upgrade setuptools or easy_install -U setuptools but nothing helped.
-
Admin over 7 yearsmy file name is cartpole.py I've imported: import tensorflow as tf and use tf.reset_default_graph()
-
martianwars over 7 yearsYou should add these details to your question. I think it's a PyCharm specific issue. Have you tried opening a python terminal in a different folder and typing
import tensorflow as tf; tf.reset_default_graph()
? -
Admin over 7 yearsi've solved an issue, thanks! the problem was in python version. it was running 2.7 by default, when my project was running on version 3.5.2 it works well when you run project like python3 and then use tensoreflow, also i made python version 3.5.2 by default
-
Simon Forsberg over 5 years@magnp I would suggest that you write your own answer for that. Using Python 3 helped me too.
-
Loganathan almost 5 yearsThanks! This solution of upgrading tensorflow removed the error for me.. But I have 'uninstall'ed and re-'install'ed instead of --upgrade option.
-
NeStack almost 5 yearsThis suggestion didn't work for me on my colab session, since I already was using python3, but the suggestions below with
from tensorflow.keras import ...
worked -
Marcello Miorelli over 4 yearsthat is exactly what the accepted answer says, so your answer is redundant
-
Shoval Sadde over 4 yearsOn this thread? The accepted answer suggests that there might be another file named
tensorflow.py
. You probably mean that my answer is in line with the accepted answer in the thread that I link to. In such a case it is not redundant (here, on this page), because it contains a link to a more wholesome solution. -
Zain Ul Abidin about 4 yearsYeah you are right the accepted answer is not actually addressing the problem this is the actual answer
-
Debvrat Varshney almost 4 yearsHow does this answer the question?