【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()
相关推荐
kaixin_啊啊8 小时前
【零基础学AI】第 29 章——第一次调用大模型 API
人工智能
甲维斯8 小时前
Qwen4 被嘲笑了!国模被啥锁死了?
人工智能
用户956256254298 小时前
五分钟用 E2B SDK 打通沙箱:环境变量只改三行
python·api
夕阳_醉了8 小时前
Codex 客户端从装好到跑通:第三方 API 接入与配置避坑指南
人工智能·gpt·openai·codex·ai 编程
熟的生菜8 小时前
从零造一个腱绳驱动灵巧手——仿真器篇5:姿势串与手势工程——从文本协议到握拳、OK 与多姿势插值
人工智能
用户95179422510299 小时前
最小循环:让 Agent 跑起来(I1)
python·agent
沉默小管9 小时前
上班鼓励器_桌宠版
python
SomeOtherTime9 小时前
Rust 面向对象介绍(AI回答)
开发语言·python·rust
武子康9 小时前
攻击动作做对了,游戏规则就对了吗?H3-World 与三条控制路线的分工
大数据·人工智能·agent
duansamve9 小时前
Flask中视图函数接收请求数据和返回响应实例
python·flask