【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 分钟前
Python爬虫中Xpath用法之——normalize-space()
开发语言·python
dozenyaoyida5 分钟前
AI与大模型新闻日报 | 2026-07-10
人工智能·chatgpt·新闻
2401_8595062412 分钟前
五轴联动数控机床的技术评估与选型分析
人工智能
ai产品老杨14 分钟前
GB28181接入AI视频分析项目实战记录:从国标注册、通道同步到信令调优
人工智能·音视频
华清远见IT开放实验室17 分钟前
从嵌入式到具身智能:嵌入式AI机器狗FS_D2,一站式打通高校嵌入式+AI+机器人教学全链路
人工智能·ai·嵌入式·实验室·具身智能·高校
想会飞的蒲公英23 分钟前
回归模型怎样评估:MAE、MSE、RMSE 和 R²
人工智能·python·机器学习·数据分析·回归
weixin_4223293126 分钟前
AgentScope Java 项目入门 & Builder 深度解读
java·开发语言·人工智能
阳明山水28 分钟前
从论文到生产:销量预测系统的工程化落地实践
大数据·人工智能·深度学习·机器学习·架构
Token炼金师29 分钟前
范式跃迁:从标注囚徒到自监督信徒 —— 大模型时代的机器学习重写
人工智能·深度学习·llm