【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()
相关推荐
FreakStudio4 分钟前
把 Flask 搬进 ESP32,高中生自研嵌入式 Web 框架 MicroFlask !
python·单片机·嵌入式·cortex-m3·异步编程·电子diy
yukai080087 分钟前
【203篇系列】050 关于量化的一些思考
人工智能
罗小罗同学31 分钟前
哈工大团队联合德累斯顿工业大学联合发布医学AI智能体综述,讲述计算病理如何从图像分类任务演变成自主诊段工作流
人工智能·分类·数据挖掘·医学图像处理·医学人工智能·医工交叉·医学ai
wincheshe39 分钟前
AI Agent 开发学习 --- 框架开发实践(三)
人工智能·学习
新缸中之脑44 分钟前
Autoresearch 代码深度解析
人工智能
love530love44 分钟前
OpenClaw 手机直连配置全流程
人工智能·windows·python·智能手机·c#·agent·openclaw
VillanelleS1 小时前
AI工程化之Agent架构
人工智能·架构
chushiyunen1 小时前
python中的内置属性 todo
开发语言·javascript·python
2301_793804691 小时前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
余俊晖1 小时前
多模态大模型后训练强化学习训练方法:Shuffle-R1
人工智能·自然语言处理·多模态