【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()
相关推荐
Ivanqhz5 分钟前
DRN(深度强化学习推荐网络)
人工智能·线性代数·机器学习·矩阵·dnn
xd1855785558 分钟前
梦境解析师-基于鸿蒙的梦境心理分析应用开发实践
人工智能·华为·harmonyos·鸿蒙
147API11 分钟前
ChatGPT Skills开放后,开发团队先补权限和上传检查
人工智能·chatgpt
嘘嘘出差12 分钟前
Python 爬虫入门实战:爬取豆瓣电影 Top 250
开发语言·爬虫·python
爱写代码的倒霉蛋17 分钟前
实现协程的三种方式
开发语言·python
ltqvibe20 分钟前
怎么让本体语义变成可执行的智能体
java·人工智能·本体语义
console.log('npc')22 分钟前
网页移动端UI/UX Pro Max - 设计智能skill
前端·人工智能·ui·ux
qiaozhangmenai35 分钟前
2026年AI超级公司系统行业趋势与技术演进分析|AI营销闭环|乔掌门AI
大数据·人工智能
顿哥GPT37 分钟前
ChatGPT 与 Codex:从编译器视角理解 AI Agent 的任务调度模型
人工智能·chatgpt
崖边看雾41 分钟前
记录Python学习——第一章环境安装下载(Windows)
windows·python·学习·pycharm