【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()
相关推荐
FreeBuf_7 分钟前
从“策略对抗”到“模型对抗”:朴智平台如何重塑金融风控新范式?
大数据·人工智能
GJGCY2 小时前
金融智能体的技术底座解析:AI Agent如何实现“认知+执行”闭环?
人工智能·经验分享·ai·金融·自动化
SteveRocket3 小时前
Python机器学习与数据分析教程之pandas
python·机器学习·数据分析
koo3643 小时前
李宏毅机器学习笔记32
人工智能·笔记·机器学习
长桥夜波3 小时前
机器学习日报04
人工智能·机器学习
Cathyqiii5 小时前
Diffusion-TS:一种基于季节性-趋势分解与重构引导的可解释时间序列扩散模型
人工智能·神经网络·1024程序员节
数字冰雹5 小时前
数字孪生技术 重构 智能仓储新生态
人工智能·重构
bulucc5 小时前
一个简答的意图识别Agent
python·大模型·agent
Lizhihao_5 小时前
Python如何写Selenium全攻略
开发语言·python