machine-learning - 属性错误: module 'tensorflow' has no attribute 'placeholder'

标签 machine-learning keras deep-learning

我正在 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/

相关文章:

python - 如何在Python中使用多标签分类器对文本进行分类?

python - scikit learn中的GridSearchCV如何选择k折的最佳参数

javascript - 喀拉斯-JS "Error: [Model] Model configuration does not contain any layers."

python - keras:如何编写自定义损失函数以将帧级预测聚合到歌曲级预测

python - 在 Keras 中训练多类图像分类器

python - Keras 中 Dense 和 Activation 层的区别

machine-learning - 根据人口统计数据对用户进行分类

machine-learning - 在监督学习中转换/缩放目标变量的好处?

tensorflow - 关于 keras 模型 : __call__ vs. 调用与预测方法的混淆

python - Keras 图像增强 : How to choose "steps per epoch" parameter and include specific augmentations during training?