【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 分钟前
RAGFlow 项目全景报告:从文档解析引擎到 Agent 原生数据库
后端·python
阿里云大数据AI技术1 小时前
EMR Serverless StarRocks + DLF Paimon 多模态数据湖检索
人工智能
文青的青1 小时前
不写一行代码,用 WorkBuddy 搭建并上线个人静态博客
人工智能
IT_陈寒1 小时前
Redis连接池泄漏那次,我差点把生产环境搞崩了
前端·人工智能·后端
Dawson Zhu1 小时前
从空间 Scaling 到时间 Scaling
人工智能·语言模型·架构·aigc·agi
灿飞屋2 小时前
Kotlin与Java虚拟机三:控制流
android·java·开发语言·后端·python·kotlin·安卓
benchmark_cc2 小时前
单只股票五档盘口接入个人研究仓库:QuantDash 读取、校验与易错点
python·数据分析·pandas·量化交易·股票数据·quantdash
阿里云大数据AI技术2 小时前
本体如何落地?阿里云 Milvus 把企业文档变成知识图谱和 Wiki
人工智能
QXWZ_IA2 小时前
公安视频专网如何与定位数据融合?架构与实施要点
人工智能
小林ixn2 小时前
GraphRAG 实战:用 Neo4j 知识图谱,让 RAG 从“找货“进化到“梳理关系“
人工智能·知识图谱·neo4j