【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()
相关推荐
人工智能培训12 小时前
基于Transformer的人工智能模型搭建与fine-tuning
人工智能·深度学习·机器学习·transformer·知识图谱·数字孪生·大模型幻觉
板面华仔12 小时前
机器学习入门(二)——逻辑回归 (Logistic Regression)
python·机器学习
Hgfdsaqwr12 小时前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python
emma羊羊12 小时前
【AI技术安全】
网络·人工智能·安全
玄同76512 小时前
告别 AgentExecutor:LangChain v1.0+ Agent 模块深度迁移指南与实战全解析
人工智能·语言模型·自然语言处理·langchain·nlp·agent·智能体
GHZhao_GIS_RS12 小时前
python中的sort和sorted用法汇总
python·排序·列表
永恒的溪流13 小时前
环境出问题,再修改
pytorch·python·深度学习
ruxshui13 小时前
Python多线程环境下连接对象的线程安全管理规范
开发语言·数据库·python·sql
Fxrain13 小时前
[Reading Paper]FFA-Net
图像处理·人工智能·计算机视觉
GISer_Jing13 小时前
Memory、Rules、Skills、MCP如何重塑AI编程
前端·人工智能·aigc·ai编程