【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()
相关推荐
光影少年27 分钟前
AI前端开发需要会哪些及未来发展?
前端·人工智能·前端框架
hqyjzsb31 分钟前
2026年AI证书选择攻略:当“平台绑定”与“能力通用”冲突,如何破局?
大数据·c语言·人工智能·信息可视化·职场和发展·excel·学习方法
独自归家的兔32 分钟前
基于 cosyvoice-v3-plus 的简单语音合成
人工智能·后端·语音复刻
民乐团扒谱机32 分钟前
【微实验】Python——量子增强时频传递的精度量化
人工智能·python·aigc·量子力学·时空·参数敏感性·光量子
G***技34 分钟前
杰和IB3-771:以RK3588赋能机场巡检机器人
人工智能·物联网
Feibo20111 小时前
管理agent
python
牛奔1 小时前
Linux 的日志分析命令
linux·运维·服务器·python·excel
电化学仪器白超1 小时前
20251209Ver8(精密电流源温漂特性测试报告)
python·单片机·嵌入式硬件·自动化
xinyaokeji1 小时前
认准高精度:基恩士 VL 扫描仪为三维测量优选之选
大数据·人工智能
mubei-1231 小时前
万字RAG综述:大语言模型的检索增强生成
人工智能·llm·rag·检索增强生成