【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()
相关推荐
程序员杰哥7 分钟前
接口自动化测试项目框架详解
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
睿智的羊9 分钟前
Cove API 的 RAG 模块拆解:一套面向 Agent 的可组合知识检索工具体系
人工智能
love530love11 分钟前
AI Agent + 本地 ComfyUI 无头模式实战:关闭 IDE 后 AI 独立重启并完成图文生成
ide·人工智能·windows·python·音视频·agent·devops
FriendshipT11 分钟前
Ultralytics:解读Attention模块
人工智能·pytorch·python·深度学习·目标检测
生活爱好者!13 分钟前
AI加持的笔记工具,比备忘录好用,NAS一键部署blinko
人工智能·笔记
IT_陈寒14 分钟前
SpringBoot自动配置没生效?你可能漏了这个注解
前端·人工智能·后端
今日综合15 分钟前
2026精选教务管理系统深度分析:功能差异、收费模式全拆解
大数据·人工智能
SilentSamsara19 分钟前
模型部署方案选型:REST/gRPC/批量推理/边缘部署的场景决策
人工智能·深度学习·算法·机器学习
多年小白19 分钟前
第八篇 模拟面试套卷
人工智能·ai·面试·职场和发展
许彰午21 分钟前
73_Python爬虫Scrapy框架入门
爬虫·python·scrapy