【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()
相关推荐
凌云拓界2 分钟前
TypeWell全攻略(四):AI键位分析,让数据开口说话
前端·人工智能·后端·python·ai·交互
heimeiyingwang6 分钟前
企业 AI 预算规划:如何分配资源实现最大 ROI
大数据·人工智能
咚咚王者7 分钟前
人工智能之视觉领域 计算机视觉 第十四章 人脸检测
人工智能·计算机视觉
码界筑梦坊10 分钟前
220-基于Python的诺贝尔奖数据可视化分析系统
开发语言·python·信息可视化·数据分析·毕业设计·fastapi
风轻扬77716 分钟前
SqlAlchemy异步IO
python·异步io
土拨鼠烧电路18 分钟前
笔记06:市场部的战争:流量、心智与增长黑客
大数据·人工智能·笔记
狙击主力投资工具19 分钟前
2026年中信里昂证券风水指数
人工智能
276695829224 分钟前
微博评论采集
开发语言·python·微博·微博评论·微博评论采集
技术程序猿华锋26 分钟前
OpenClaw (CloudBot) 国内完美运行指南:自定义API 代理与飞书协同部署
人工智能·飞书·openclaw
一只理智恩27 分钟前
WebGIS + 无人机 + AI:下一代智能巡检系统?
人工智能·无人机