【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()
相关推荐
Dante但丁1 分钟前
手扒Github项目文档级知识图谱构建框架RAKG(保姆级)Day4
人工智能
用户5191495848459 分钟前
使用JavaScript与CSS创建"移动高亮"导航栏
人工智能·aigc
Java中文社群17 分钟前
淘宝首位程序员离职,竟投身AI新公司做这事!
人工智能·后端·程序员
失散1329 分钟前
自然语言处理——02 文本预处理(上)
人工智能·自然语言处理
Listennnn1 小时前
nuScence数据集
人工智能
duration~1 小时前
SpringAI集成MCP
人工智能·后端·spring·ai
Ratten1 小时前
【Python 实战】---- 实现一个可选择、配置操作的批量文件上传工具(四)配置管理界面和逻辑实现
python
Ratten1 小时前
【Python 实战】---- 实现一个可选择、配置操作的批量文件上传工具(五)打包成 exe 应用
python
用户5191495848451 小时前
Linux内核UAF漏洞利用实战:Holstein v3挑战解析
人工智能·aigc
跟橙姐学代码1 小时前
写 Python 函数别再死抠参数了,这招让代码瞬间灵活
前端·python