I have installed tensorflow version r0.11.
In my file name cartpole.py
I have imported tensorflow
:
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?
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.
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()
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()
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()
Change your import to tensorflow.keras For example From keras import Sequential to From tensorflow.keras import Sequential
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With