AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘ 问题时的方法,亲测有效!!!不妨一试

当你出现这个问题时,说明在TensorFlow2.0下使用了TensorFlow1.0的API
AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘ 问题时的方法,亲测有效!!!不妨一试
这个时候我们可以试试以下办法
方法:
将import tensorflow as tf
替换成
import tensorflow.compat.vl as tf
tf.disable_v2_behavior()
以下是我修改后的运行情况:AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘ 问题时的方法,亲测有效!!!不妨一试
可以看到,已经可以正常运行了。(还没运行完,结果不重要,重要的是可以正常run了,嘻嘻嘻)

ps:上面两行的替换实则是将tf2.0向下兼容为tf1.0了。