【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()
相关推荐
独隅几秒前
Keras 的主要特点和适用场景
人工智能·深度学习·keras
车斗几秒前
连载(6):《万物皆事件(AE):“怀特海过程”的实现与“映射哲学”的形式化证明》—— 面向AI的智能体特性——统一的可信智能架构
人工智能·可信ai·aiae·万物皆事件·怀特海·时空引擎
FluxMelodySun8 分钟前
机器学习(二十九) 稀疏表示与字典学习(LASSO算法、KSVD算法、奇异值分解)
人工智能·算法·机器学习
fzil00110 分钟前
为什么 Claude Code 选择 Bun 而非 Node.js?—— 运行时选型的技术考量
人工智能
程序设计实验室21 分钟前
Python网络请求库,从 requests 到 httpx
python
电商API&Tina25 分钟前
跨境电商如何接入1688官方寻源通接口?附接入流程
java·数据库·python·sql·oracle·json·php
猿饵块28 分钟前
机器人--cfg参数
人工智能·机器人
查古穆35 分钟前
LLM的“小bug”:聊聊幻觉是什么,以及如何有效规避免
人工智能·bug
环黄金线HHJX.37 分钟前
【从0到1】
开发语言·人工智能·算法·交互