【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 tf为import 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()
相关推荐
小oo呆10 分钟前
【学习心得】Python协程
python
IT_陈寒11 分钟前
Redis的LRU淘汰策略坑了我一整天
前端·人工智能·后端
墨抒颖 msy.plus12 分钟前
矩阵、注意力与 GPU:拆解 DeepGEMM 与 FlashMLA
人工智能·llm·gpu·源码解析·1024程序员节·deepseek
甲维斯22 分钟前
K3.1pro你这“机灵鬼”,3D建模无敌了!
人工智能
企业数字化笔记23 分钟前
AI视频卡顿怎么定位?用帧差和时间戳区分静帧与播放问题
人工智能
信誓旦旦的程序猿26 分钟前
【Python量化实战宝典 #22】涨跌停、连板情绪手册:情绪指标构建(Python 可跑)
python·1024程序员节·股票数据api·股票数据api接口·股票api数据接口·股票量化数据api·股票量化数据接口
gCode Teacher 格码致知30 分钟前
Pandas教学-21:subplots的使用
python·pandas·1024程序员节
2601_9679801134 分钟前
Python开发的顶级开源项目全景图:2025-2026年生态概览
python·机器学习·开源项目·数据科学·生态概览
一级新生36 分钟前
提示词工程:跟 AI 打交道的手艺
人工智能·大模型·dify·1024程序员节·提示词工程
Tangyuewei1 小时前
AI 编程后,越来越不会码了
人工智能·ai编程