Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 399
magnp Avatar asked Nov 24 '16 09:11

magnp


5 Answers

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.

like image 79
Shoval Sadde Avatar answered Nov 11 '22 11:11

Shoval Sadde


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()
like image 40
martianwars Avatar answered Nov 11 '22 11:11

martianwars


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()
like image 9
Bhadru Bhukya Avatar answered Nov 11 '22 10:11

Bhadru Bhukya


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()
like image 7
Himanshu Avatar answered Nov 11 '22 11:11

Himanshu


Change your import to tensorflow.keras For example From keras import Sequential to From tensorflow.keras import Sequential

like image 5
Chinmay Avatar answered Nov 11 '22 11:11

Chinmay