AttributeError: module tensorflow has no attribute placeholder TensorFlow 2.0

This error may come if you have installed TensorFlow 2.0 and want to run code that is not compatible with TensorFlow 2.0

For example if you are trying to run below code, you will get the above error.

x = tf.placeholder("float", None)

The sample error is shown in the Image below

Attribute Error TensorFlow 2.0

To fix this we need to use the below code

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

Then if you run the same code it will not give you error as below

You may like to read our other popular posts as below:

  1. Linear Regression in Python in 10 Lines
  2. Logistic Regression In Python in 10 Lines
  3. Generating Synthetic Data for Logistic Regression
  4. Scatter Plot using Seaborn and Sklearn

I hope you enjoyed this article and can start using some of the techniques described here in your own projects soon.

Advertisements

Leave a Reply