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

You normally import tensorflow by writing,

import tensorflow as tf

It's possible that you have named a file in your project and the import statement is importing from this file.

Alternatively, you can try this,

from tensorflow.python.framework import ops

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


import keras.<something>.<something>


import tensorflow.keras.<something>.<something>

Where 'something' is the module you want to import

Downloading binary version of TensorFlow solved my problem.

$ pip install --ignore-installed --upgrade "<URL>"

Select right binary URL according to your system from below.

This also may caused you run your code in the wrong environment.

I install tensorflow-gpu in my ~/tensorflow virtualenv.

I can run the python3 in the env with source ./tensorflow/bin/activate

But whenI ran python3 in the env ~ without virtualenv, I sometimes may came to issues like

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


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

and some others

Instead of importing directly from keras

from keras.layers import Input

Import from tensorflow

from tensorflow.keras.layers import Input

I got this issue twice and the above one solved my issue

BhaDru PrABha

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()