【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()
相关推荐
敲敲敲敲暴你脑袋4 小时前
穷鬼快乐AI工具Ollama
javascript·人工智能·ollama
2401_898075124 小时前
Python在金融科技(FinTech)中的应用
jvm·数据库·python
Struart_R4 小时前
Spann3R、MUSt3R、CUT3R、TTT3R论文解读
人工智能·计算机视觉·3d·三维重建·前馈模型
大鹏的NLP博客4 小时前
工业级时间序列利器之一:深入解析 TCN 及其注意力增强实现
人工智能·深度学习
xier_ran4 小时前
【第二周】 RAG与Agent实战16:ChatPromptTemplate的使用 —— 打造有记忆的AI
人工智能·langchain·rag
测试_AI_一辰4 小时前
AI系统测试:LLM 在系统中负责什么,怎么测试?
人工智能·功能测试·ai·ai编程
软件资深者4 小时前
Coze自动化工作流+Agent智能体实战教程(0基础入门,附多场景实操)
运维·人工智能·ai·自动化·工作流·扣子·课程
老师好,我是刘同学5 小时前
选择排序原理与Python实现
python·排序算法
2501_948114245 小时前
OpenClaw + 星链4SAPI:打造AI自动化“智能体舰队”,从数据采集到模型调度的终极实战
大数据·人工智能