【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()
相关推荐
孟健22 分钟前
实测 agent-desktop:AI 控制桌面不截图、不占鼠标键盘,连点 55 次计算器 0 失误
人工智能·架构·开源
MUSHANGXS29 分钟前
大模型时代的新蓝海-基于OS底层的AI-Agent应用
人工智能·职场和发展·交互
维克兜率天37 分钟前
【维克】复合型CTA:趋势+套利的双轮驱动
python·学习方法
伞伞悦读38 分钟前
【第76期】两张3行表左连接变5行:主键、validate与未匹配排查完整教程
人工智能·python
IT_陈寒1 小时前
Redis大key删除为什么会导致服务卡顿?我的线上事故复盘
前端·人工智能·后端
用户8356290780511 小时前
使用 Python 在 Excel 中添加和自定义迷你图
后端·python
阿里云大数据AI技术2 小时前
云栖实录 | AgenticSearch 定义 AI 搜索时代的信息检索 - 新范式
人工智能
用户8356290780512 小时前
使用 Python 在 Excel 图表中添加趋势线与回归方程
后端·python
AI源码2 小时前
基于深度学习的音乐风格分类系统
人工智能·深度学习
慢慢来不要急2 小时前
GitHub Copilot Fusion 智能路由模型 · 11-02
人工智能·开发工具