【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()
相关推荐
宁渡AI大模型40 分钟前
河南宁渡科技有限公司|宁渡课堂 AI 全栈面试分享,RAG 项目面试深挖问题解析
人工智能·机器学习·rag
锋行天下7 小时前
LangGraph 1.2+ 新特性:set_node_defaults,批量统一节点策略
人工智能
找方案7 小时前
AI+人力资源:AI招聘面试的兴起与争议
人工智能·面试·职场和发展
日常通勤穿搭7 小时前
2026 电商 AI 作图工具推荐|淘宝抖音跨境商品主图 AI 生图测评
人工智能·aigc·ai工具·电商美工
ZhengEnCi7 小时前
L2A-一个域名如何访问多台云服务器-子域名、路径前缀与Nginx反向代理选型指南
linux·人工智能
2601_963749107 小时前
越华环保集团污水站曝气系统边缘闭环控制架构与能耗优化实现
人工智能·架构
花酒锄作田7 小时前
FastAPI 使用 session 认证
python·fastapi
工业涂料百问7 小时前
【生产施工】系列(六)工业涂料固化方式怎么选?自然干 / UV / 电子束原理与选型实战
人工智能
lsswear7 小时前
Python 并发 线程
开发语言·python
葡萄城技术团队8 小时前
活字格 12.1 新特性解密:禁用自动回复后,AI 对话单元格也能流式输出了
人工智能