【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()
相关推荐
曲幽1 小时前
FastAPI 身份验证总踩坑?这份 FastAPI Users “避坑指南”请收好
python·fastapi·web·jwt·oauth2·user·authentication
WPF工业上位机1 小时前
YXGK.FakeVM深度学习之5语义分割
人工智能·深度学习
落叶无情1 小时前
ICEF认知操作系统:四类约束全维度全覆盖,是全谱系系统化约束体系
人工智能
碳基硅坊1 小时前
Gemma 4 12B 让AI创作更私密更高效
人工智能·gemma-4-12b
weixin_468466851 小时前
大模型新手入门与实战指南
人工智能·深度学习·ai·大模型
装不满的克莱因瓶1 小时前
掌握 RNN 与 LSTM 模型结构
人工智能·python·rnn·深度学习·神经网络·ai·lstm
jeffer_liu1 小时前
Spring AI 生产级实战:裁判员
java·人工智能·后端·spring·大模型
何以解忧,唯有..1 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
weixin_446260852 小时前
Agent 会自行回避吗?测量 LLM 智能体合规性的带内访问拒绝信号
人工智能
金銀銅鐵2 小时前
用 Tkinter 实现简单的猜数字游戏
后端·python