【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()
相关推荐
雾游2 分钟前
用上 uv 后,搭建 Python 项目终于顺手了:从安装到环境恢复,一篇讲清
python
范中勤3 分钟前
LangGraph Checkpointer 封装(下):with 的双层上下文与 MemorySaver 为什么不用 with
python·大模型·llm·agent·langgraph
鸿业远图科技8 分钟前
丹东市_公交线
python
通信大模型9 分钟前
面向AI原生6G网络的可解释任务导向型Token通信
人工智能·计算机视觉
Magician_liu18 分钟前
机器学习基本概念
人工智能·机器学习
Industio_触觉智能19 分钟前
瑞芯微AI算力NPU路线图与协处理器|触觉智能瑞芯微RK方案商出品
人工智能·嵌入式硬件·硬件架构·智能硬件·npu·瑞芯微·端侧ai
EchoMind-Henry25 分钟前
EviScene:识别出AI图,不等于查明真假
人工智能
打工仔折腾 AI27 分钟前
在线PDF工具隐私焦虑?把BentoPDF部署到极空间NAS本地处理
人工智能·后端·python·pdf·ai agent 实战
AI视频工具指南33 分钟前
AI短剧怎么做?一个矛盾怎样接着讲三集
人工智能·aigc·音视频
2603_9651481137 分钟前
商品价格监控 API 接口:从原理到实战的完整指南
java·前端·数据库·python·生活