module ‘tensorflow’ has no attribute ‘get_default_graph’

You may catch the following error when creating a model with Tensorflow/Keras:

module 'tensorflow' has no attribute 'get_default_graph'

Solution #1: Try to use from tensorflow.keras instead of from keras when importing libs.

Solution #2: Because Tensorflow V2 does not support that ‘get_default_graph’ function, in order to use it in v2, try to use it like:

tf.compat.v1.get_default_graph()

instead of 

tf.get_default_graph()

or

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

Insted of:

import tensorflow as tf

More Articles

How to start a new Github repo from an existing project

Assume that you have a project and you want to track it with Github. Navigate to the project folder,...

codezilla

codezilla

How to check for listening ports in Linux

Here is one of the most popular commands for troubleshooting network or specific application problem...

codezilla

codezilla

How to get octal file permissions from command line?

Sometimes we want to know the octal number representing the permission of a file like 755, 777, 664 ...

codezilla

codezilla