AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘ [How to Solve]


When you have this problem, it indicates that TF1 API is used under TF2

1. See if the version number is used incorrectly

In pychar, find the project, and then output the following command to see the version

import tensorflow as tf  #Load the tensorflow environment

print(tf.__version__) #View tensorflow version

If it is shown in the figure below, you are using TF2

2. Put the code into the following code in TF environment

import tensorflow as tf

Replace with the following code

import tensorflow.compat.v1 as tf

Run the program. The procedure is correct


Similar Posts: