【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 小时前
AI提示词(Prompt)入门:什么是Prompt?为什么要写好Prompt?
人工智能·aigc·ai写作·ai工具集·最新ai资讯
Devlive 开源社区2 小时前
技术日报|Claude Code超级能力库superpowers登顶日增1538星,自主AI循环ralph爆火登榜第二
人工智能
软件供应链安全指南2 小时前
灵脉 IAST 5.4 升级:双轮驱动 AI 漏洞治理与业务逻辑漏洞精准检测
人工智能·安全
lanmengyiyu2 小时前
单塔和双塔的区别和共同点
人工智能·双塔模型·网络结构·单塔模型
微光闪现3 小时前
AI识别宠物焦虑、紧张和晕车行为,是否已经具备实际可行性?
大数据·人工智能·宠物
技术小黑屋_3 小时前
用好Few-shot Prompting,AI 准确率提升100%
人工智能
中草药z3 小时前
【嵌入模型】概念、应用与两大 AI 开源社区(Hugging Face / 魔塔)
人工智能·算法·机器学习·数据集·向量·嵌入模型
web3.08889993 小时前
微店商品详情API实用
python·json·时序数据库
知乎的哥廷根数学学派3 小时前
基于数据驱动的自适应正交小波基优化算法(Python)
开发语言·网络·人工智能·pytorch·python·深度学习·算法
DisonTangor4 小时前
GLM-Image:面向密集知识与高保真图像生成的自回归模型
人工智能·ai作画·数据挖掘·回归·aigc