【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 tf为import 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()
相关推荐
开开心心就好2 分钟前
办公软件卸载不干净?专用工具一键清残留
java·前端·人工智能·智能手机·kafka·excel·memcache
机核研创社3 分钟前
接橡筋机做内裤腰头明橡筋:两段式工艺链的设备分工与参数窗口拆解
人工智能·自动化
海宇数据13 分钟前
零信任架构实战:基于海宇活体识别V步骤1构建自动化考前活体认证网关
运维·人工智能·架构·自动化
Duckdblab13 分钟前
我用 Cloudflare Worker 搭了个 AI 网关,白嫖 Agnes + DeepSeek 双模型,还能给 Hermes 用
人工智能
bullkingluo14 分钟前
从零到一搭建企业级智能问答系统:Ch12 · 结构化输出与工具调用
人工智能·架构·llm
坤坤子吖14 分钟前
Python基础语法学习:条件、循环与程序控制
开发语言·笔记·python·学习
桃西西呀16 分钟前
LangChain 之五:智能体与工具
人工智能·langchain·llm
bullkingluo17 分钟前
从零到一搭建企业级智能问答系统:Ch11 ·大模型调参与效果评测
人工智能·架构·llm
模拟器连接器曾工21 分钟前
一进多出M12分线盒4口8口12口可选 PNP和NPN通用传感器集线器
网络·人工智能·m12分线盒·npn通用传感器集线器·pnp通用传感器集线器
回眸&啤酒鸭22 分钟前
GLM 5.3 Flash 批量处理实战指南
大数据·人工智能