【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()
相关推荐
LDG_AGI12 分钟前
【人工智能】OpenClaw(一):MacOS极简安装OpenClaw之Docker版
运维·人工智能·深度学习·机器学习·docker·容器·推荐算法
一水鉴天14 分钟前
智能代理体系 之2 20260325 (腾讯元宝)
人工智能·重构·架构·自动化
Monster丶62614 分钟前
Docker 部署 Ollama 全流程指南:支持 CPU/GPU、生产环境可用的工程化实践
运维·人工智能·docker·容器
科雷软件测试22 分钟前
Midscene.js - AI驱动,带来全新UI自动化体验(安装配置篇)
javascript·人工智能·ui
Java后端的Ai之路25 分钟前
【AI应用开发】-怎么解决Lost in the Middle(中间迷失)现象?
人工智能·agent·rag·中间迷失·lost
2401_8747325329 分钟前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
HinsCoder35 分钟前
【miclaw】——小米手机龙虾配置教程
人工智能·智能手机·llm·agent·openclaw·miclaw·手机龙虾
TMT星球37 分钟前
从智能出行到智能家电,探路生态携智能空间全栈产品矩阵亮相AWE
大数据·人工智能·矩阵
AI-Ming1 小时前
程序员转行学习AI大模型:位置编码
人工智能·神经网络·学习
平常心cyk1 小时前
Python基础快速复习——集合和字典
开发语言·数据结构·python