【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()
相关推荐
不可求~1 分钟前
用 AI 读论文别只看摘要:建立可追溯的证据链
人工智能·深度学习·机器学习
狙击主力投资工具2 分钟前
通达信软件手机app和电脑使用手册教程.内含160多个.mpv版使用手册
人工智能
飞翔的火箭弹3 分钟前
伊顿电力模块技术参数深度解析:AI算力时代高集成供配电方案选型参考
人工智能
今天AI了吗13 分钟前
Python 基础语法(一):常量、变量、输入输出与运算符
开发语言·数据库·人工智能·python·sql·深度学习·机器学习
Warren2Lynch15 分钟前
从提示词到架构:Visual Paradigm VPasCode AI 驱动更新完全指南
人工智能·架构
卷无止境21 分钟前
Windows 上丝滑开发 Python,并稳定构建 Docker 镜像
后端·python·docker
ZGIAI23 分钟前
ZGI 发布治理:同一个 Agent 服务多个入口
人工智能·架构
ZGIAI30 分钟前
ZGI 批量测试:上线前验证 Agent
人工智能·架构
qq4078556030 分钟前
面向智能补货需求的进销存系统盘点
大数据·人工智能·低代码·制造
TELL5211 小时前
selenium webdriver 第二次初始化的异常
开发语言·python