【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()
相关推荐
cooldream20094 分钟前
AI 时代,Git 应该怎么学
人工智能·git
小保CPP4 分钟前
OpenCV C++计算多边形的最大内切圆
c++·人工智能·opencv·计算机视觉
像风一样自由20207 分钟前
2.时序异常检测入门到实战:评估的陷阱:point-adjust 如何把烂模型刷成 SOTA
人工智能·时序异常检测·时间序列模型
第七页独白10 分钟前
AI 赋能 APQP 项目管控!全星研发项目管理系统为制造企业创造多重核心价值
人工智能
心疼你的一切20 分钟前
Build-Your-Own-X 实战指南:从复刻经典到掌握核心原理
人工智能·ai·aigc
鲜于言悠90522 分钟前
Anthropic深夜王炸:Claude Opus 5上线,自带代码自检程序员福音
人工智能
雪隐24 分钟前
AI股票小助手10-我用代码管住自己的手:一个普通人的市场观察笔记
前端·人工智能·后端
方方洛25 分钟前
AI 教程系列-TUI 应用开发教程02-终端基础
人工智能
DogDaoDao32 分钟前
【GitHub】WorldMonitor:一个工程极致主义的实时全球情报仪表盘深度解析
python·程序员·架构·github·go语言·worldmonitor·实时全球情报
Alter123033 分钟前
从堆算力到算存网协同,华为给出了Agent时代的新解法
人工智能·华为