【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()
相关推荐
TG:@yunlaoda360 云老大2 小时前
腾讯WAIC发布“1+3+N”AI全景图:混元3D世界模型开源,具身智能平台Tairos亮相
人工智能·3d·开源·腾讯云
这张生成的图像能检测吗2 小时前
(论文速读)Fast3R:在一个向前通道中实现1000+图像的3D重建
人工智能·深度学习·计算机视觉·3d重建
兴趣使然黄小黄5 小时前
【AI-agent】LangChain开发智能体工具流程
人工智能·microsoft·langchain
出门吃三碗饭5 小时前
Transformer前世今生——使用pytorch实现多头注意力(八)
人工智能·深度学习·transformer
l1t5 小时前
利用DeepSeek改写SQLite版本的二进制位数独求解SQL
数据库·人工智能·sql·sqlite
ζั͡山 ั͡有扶苏 ั͡✾5 小时前
从零搭建 Data-Juicer:一站式大模型数据预处理与可视化平台完整教程
python·data-juicer
说私域5 小时前
开源AI智能名片链动2+1模式S2B2C商城小程序FAQ设计及其意义探究
人工智能·小程序
SkylerHu6 小时前
tornado+gunicorn部署设置max_body_size
python·tornado·gunicorn
开利网络6 小时前
合规底线:健康产品营销的红线与避坑指南
大数据·前端·人工智能·云计算·1024程序员节
非著名架构师6 小时前
量化“天气风险”:金融与保险机构如何利用气候大数据实现精准定价与投资决策
大数据·人工智能·新能源风光提高精度·疾风气象大模型4.0