【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 小时前
Miniconda安装与使用教程
python
财经资讯数据_灵砚智能1 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月8日
大数据·人工智能·python·信息可视化·自然语言处理
其实防守也摸鱼1 小时前
软件安全与漏洞--实验 软件安全设计
开发语言·网络·python·安全·软件安全·实验·软件安全设计
Jason_zhao_MR1 小时前
RK3576 MIPI Camera ISP调试:客观标定与环境准备(上)
人工智能·嵌入式硬件·机器人·嵌入式·接口隔离原则
Mr数据杨1 小时前
【CanMV K210】AI 视觉 YOLO 口罩佩戴状态识别
人工智能·硬件开发·canmv k210
金智维科技官方1 小时前
金智维入选IDC金融生成式AI全景图谱,智能体走向自主执行新阶段
大数据·人工智能·金融
DogDaoDao1 小时前
【GitHub】TextGen:开源本地大模型运行平台的终极解决方案
人工智能·深度学习·自然语言处理·开源·大模型·github·textgen
wuxinyan1231 小时前
大模型学习之路008:RAG 零基础入门教程(第五篇):完整 Naive RAG 系统搭建与评估
人工智能·学习·rag
PersistJiao1 小时前
2026年 AI 编程工具格局
人工智能
不会飞的鲨鱼1 小时前
观鸟网 RSA加密 AES 解密
javascript·爬虫·python