Python 报错 AttributeError: module “tensorflow“ has no attribute “placeholder“
报错:
Placeholder的中文意思就是占位符,用于在会话运行时动态提供输入数据。Placeholder相当于定义了一个位置,在这个位置上的数据在程序运行时再指定。但是由用户在调用run方法是传递的,也可以将placeholder理解为一种形参。即其不像constant那样直接可以使用,需要用户传递常数值。
解决办法:
Tensorflow 1.x 版本提供placeholder,而 2.0版本暂时没有这个模块。所以把Tensorflow 换回 1.x版本即可。
所以在导包的时候我们进行修改一下就可以了,将
import tensorflow as tf
改为:
import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
亲测有用!!!!
还没有评论,来说两句吧...