How to resolve: AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’

less than 1 minute read

Issue


  • As tensorflow has been updated to 2.x, it no longer supports tf.placeholder.
  • the code above will raise an error that placeholder cannot be found.

There are two ways to get around this issue.

Solution 1: to follow the update scheme of Tensorflow 2.0


First method is apply changes in Tensorflow 2.0. Please refer to the details on the update this link.

placeholder can be replaced by variable as shown below.

Solution 2: to use compatibility mode


The second method is to disable the updated features in 2.0 by applying compatibility mode **. This can be implemented as following, then you will still be able to declare **tf.placeholder.