【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()
相关推荐
chaors1 小时前
从零学RAG0x03第一个实战应用:医疗知识混合检索实战
人工智能·aigc·ai编程
阿聪谈架构1 小时前
第02章:Prompt 工程 —— 用语言精准指挥 AI
人工智能
dev派1 小时前
AI Agent 系统中的常用 Workflow 模式(2) Evaluator-Optimizer模式
python·langchain
suke1 小时前
AI 界的 npm 惨案重演?聊聊 龙虾OpenClaw skills那些带毒的“骚操作
人工智能·程序员·aigc
明明如月学长1 小时前
OpneClaw 总挂?配个"保镖"自动修,7x24小时不用管
人工智能
万少2 小时前
用 OpenClaw 实现小红书自动发帖
人工智能
阿聪谈架构3 小时前
第01章:从零开始调用 LLM —— 入门 Qwen 大模型 API
人工智能
前端付豪3 小时前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户0332126663673 小时前
将 PDF 文档转换为图片【Python 教程】
python
七牛云行业应用3 小时前
保姆级 OpenClaw 避坑指南:手把手教你看日志修 Bug,顺畅连通各大 AI 模型
人工智能·后端·node.js