【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()
相关推荐
自律懒人4 分钟前
AI应用从原型到上线的最后一公里——灵光闪应用一键部署深度实测,30+免费API + Serverless零配置发布
人工智能·云原生·开源·serverless
大模型念念11 分钟前
Codex:AI 编程助手的核心引擎
人工智能
AndrewHZ15 分钟前
【LLM技术全景】多模态大模型:当语言模型学会“看“和“听“
人工智能·gpt·深度学习·语言模型·自然语言处理·llm·多模态
湘美书院--湘美谈教育18 分钟前
湘美谈教育互联网逻辑:AI时代的社会学猜想
大数据·人工智能·深度学习·机器学习·生活
东方佑20 分钟前
MA-RMSNorm:打破“缩放换智能”的魔咒,大模型归一化的一次范式革命!
数据库·人工智能·计算机视觉
KKKlucifer31 分钟前
多源异构通信数据统一识别:运营商分类分级平台关键技术与落地成
人工智能·分类·数据挖掘
jinggongszh32 分钟前
从长鑫科技的十年突围,看中国制造的“硬核”与“底座”
人工智能·科技·制造
程序员cxuan38 分钟前
A 社官方:我们删掉了 80% 的 skills
人工智能·后端·程序员
工业胶囊1 小时前
“AI+制造”1.0基础认知篇:通用AI与工业AI的核心差异与应用逻辑
人工智能·制造·数字化转型·工业ai
问商十三载1 小时前
AI 引擎生成式优化两种思路怎么选?2026 对比分析附选型方法
人工智能·算法