【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()
相关推荐
shangjian007几秒前
AI-大语言模型LLM-LangChainV1.0学习笔记-模型不同调用方式的差异
人工智能·学习·语言模型
flyyyya几秒前
【AI学习从零至壹】AI agent自动化工作流
人工智能·学习·自动化
coding者在努力3 分钟前
LangChain之解析器核心组件.2026年新版讲解,超详细
windows·python·机器学习·langchain·pip
Alsian5 分钟前
Day32 神经网络
人工智能·深度学习·神经网络
梦帮科技6 分钟前
【DREAMVFIA开源】量子互联网协议:节点通信与路由算法
人工智能·神经网络·算法·生成对抗网络·开源·量子计算
伶俐的猪9 分钟前
性能测试以及面试题
python
52Hz11812 分钟前
力扣394.字符串解码、739.每日温度、84.柱状图中最大的矩形
python·算法·leetcode
雨大王51212 分钟前
为什么汽车零部件需要智能制造?关键技术与发展路径探讨
大数据·人工智能
海绵宝宝_13 分钟前
Antigravity 配置VS Code 插件市场教程
人工智能·学习
2501_9269783313 分钟前
概率分形:智能涌现的统一机理
人工智能·经验分享·机器学习·ai写作·agi