【DL-TensorFlow遇错】TensorFlow中遇错合集

TensorFlow中遇错合集

  • [一、`AttributeError: module 'tensorflow' has no attribute 'placeholder'`](#一、AttributeError: module 'tensorflow' has no attribute 'placeholder')
  • [二、`RuntimeError: tf.placeholder() is not compatible with eager execution.`](#二、RuntimeError: tf.placeholder() is not compatible with eager execution.)

一、AttributeError: module 'tensorflow' has no attribute 'placeholder'

错误原因

  • tensorflow版本问题:当前tensorflow版本为2.X,而tensorflow 2.0版本去掉了placeholder。tensorflow 1.*版本才有placeholder。

解决方案

  • "向后兼容"。这种做法可以在新版本的TensorFlow中仍然使用旧的API,确保旧代码的兼容性。

具体实现

  • 修改import tensorflow as tfimport tensorflow._api.v2.compat.v1 as tf

二、RuntimeError: tf.placeholder() is not compatible with eager execution.

错误原因

  • tf.placeholder()意味着被提供给会话,该会话在运行时从feed dict接收值并执行所需的操作。(也就是默认为急切运行,我们爆出这个错误说明不需要急切运行

解决方案

方式一:

  • tf.placeholder()被调用前添加tf.compat.v1.disable_eager_execution()

方式二:

bash 复制代码
import tensorflow._api.v2.compat.v1 as tf
tf.compat.v1.disable_eager_execution()
相关推荐
LXT7122 分钟前
2026职称申报冲刺期:ChatGPT、Claude、Kimi、雷小兔同题横评
人工智能·chatgpt
sali-tec12 分钟前
C# 基于OpenCv的视觉工作流-章98-频域滤波
图像处理·人工智能·opencv·计算机视觉
Kevin Wang72715 分钟前
Nvidia-AGX-spark部署手册——课堂质量诊断(jetpack:r36)
python·docker·容器
眼泪划过的星空16 分钟前
基于 LangChain 框架构建本地化 RAG 系统:无需调用云端 API 的完整实践
人工智能·langchain
布鲁飞丝19 分钟前
彩笔运维勇闯机器学习--cpu与qps的线性关系
运维·人工智能·机器学习
ZHOU_WUYI21 分钟前
5. light wam 中video pre阶段
人工智能
2501_9269783323 分钟前
提示工程的实战报告(二):模型的失败模式与边界行为
人工智能·深度学习·算法
行走的小派30 分钟前
Zero 4不是Zero 3W的升级版,是香橙派的策略补位
人工智能·香橙派·边缘ai
IanSkunk31 分钟前
企业AI办公落地技术拆解:从WorkBuddy任务引擎到JOTO实施路径
大数据·人工智能
Mycdn_WD1 小时前
项目交付后的机房,能参与边缘节点协作吗?
人工智能·cdn·pcdn·城域网·pcdn资源招募