【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()
相关推荐
坚持学习前端日记16 分钟前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
蜡台23 分钟前
大模型算力下放客户端:浏览器/本地设备全落地方案解析
人工智能·ai
冬奇Lab32 分钟前
开源项目第191期:gstack — YC CEO Garry Tan 开源的 AI 虚拟工程团队,23 个专家角色 slash command,从产品构思到上线发布的完整研发流程
人工智能·开源·资讯
北斗落凡尘36 分钟前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
冬奇Lab1 小时前
企业知识库系列(03):图增强 RAG 实测——GraphRAG vs HippoRAG
人工智能
MomentYY1 小时前
RAG 索引维护:文档改了,知识库要不要重建?
人工智能·agent·ai编程
土星云SaturnCloud1 小时前
产线SOP动作级AI监管方案:土星云SE110S-WC8赋能合规识别、预警与效率分析
大数据·服务器·人工智能·ai·边缘计算
雪碧聊技术1 小时前
安装Python(保姆级教程)
python·版本更新·python下载
乐之者v2 小时前
AI人工智能--DeepSeek Harness的安装
人工智能·ai