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

You may like to watch a video on Neural Network from Scratch in Python

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.

Do you really think that a neural network is a block box? I believe, a neuron inside the human brain may be very complex, but a neuron in a neural network is certainly not that complex. In this video, we are going to discuss how to implement a neural network from scratch in Python.

Leave a Reply

%d bloggers like this: