使用函数
tf.placeholder(tf.float32, [None, n_input])
时报错如下
AttributeError: module 'tensorflow' has no attribute 'placeholder'
问题是我使用的是tensorflow2.0以上版本,代码中的函数是1.0的版本
解决方案,在导入tensorflow包时使用以下方式导入
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
这可以解决类似函数对应的tensorflow版本不一的问题。
这也是Tensorflow 团队提供的解决方案。