【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()
相关推荐
枕石 入梦2 分钟前
Java 手写 AI Agent:ZenoAgent 实战笔记
人工智能·开源·agent·zenoagent
七夜zippoe2 分钟前
模拟与存根实战:unittest.mock深度使用指南
linux·服务器·数据库·python·模拟·高级摸您
陈天伟教授6 分钟前
人工智能应用- 人工智能交叉:06.解析蛋白质宇宙
人工智能·神经网络·算法·机器学习·推荐算法
踩坑记录7 分钟前
leetcode hot100 17. 电话号码的字母组合 medium 递归回溯
python
hudawei99615 分钟前
和豆包AI对话-什么是人类的理解
人工智能·人类的理解·人工智能的理解
BatmanWayne18 分钟前
swift-微调补充
人工智能·swift
成都方航科技18 分钟前
AI助力非机动车交通管理解决方案 AI摄像头劝导系统 成都方航科技有限公司
人工智能·科技
Brian-coder22 分钟前
Swarm-Lab:多智能体实验平台
人工智能
牛哥带你学代码23 分钟前
Spatiotemporal Prediction using Deep Learning
人工智能·深度学习·机器学习
腾飞开源25 分钟前
104_Spring AI 干货笔记之开发时服务
人工智能·docker compose·容器管理·spring ai·testcontainers·开发时服务·ssl支持