我正在 kaggle 内核上进行面部表情识别,一切都很顺利,但突然以下代码开始出错。
import tensorflow as tf
x = tf.placeholder(shape = [None, image_pixels], dtype = tf.float32) y = tf.placeholder(shape = [None, labels_count], dtype = tf.float32)
AttributeError: module 'tensorflow' has no attribute 'placeholder'
我尝试了互联网上的许多替代方法,例如使用
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
这个而不是
import tensorflow as tf
但是一切都是徒劳。请在这里帮助我
最佳答案
将 <tf.placeholder
> 更改为 <tf.compat.v1.placeholder
>
比如
x = tf.placeholder(shape = [None, image_pixels], dtype = tf.float32)
更改为
x = tf.compat.v1.placeholder(shape = [None, image_pixels], dtype = tf.float32)
但是还有一个关于急切执行的运行时错误的问题
在导入部分后添加
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
像这样
关于machine-learning - 属性错误: module 'tensorflow' has no attribute 'placeholder' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64364703/