【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()
相关推荐
2401_873544923 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
数字时代全景窗3 小时前
Palantir:两个不确定的问题(1)大模型以上,世界模型未满?
人工智能·软件工程
和沐阳学逆向3 小时前
断层碾压 Opus!Anthropic 最强模型泄露,代号「卡皮巴拉」
人工智能
Swift社区3 小时前
鸿蒙游戏里的 AI Agent 设计
人工智能·游戏·harmonyos
剑穗挂着新流苏3123 小时前
202_深度学习的动力源泉:矩阵微积分与自动求导 (Autograd)
人工智能·pytorch·python·深度学习·神经网络
qq_148115373 小时前
Python上下文管理器(with语句)的原理与实践
jvm·数据库·python
陆业聪3 小时前
AI 时代最被低估的工程师技能:把需求写清楚
android·人工智能·aigc
qwehjk20083 小时前
机器学习模型部署:将模型转化为Web API
jvm·数据库·python
艾莉丝努力练剑3 小时前
alarm系统调用的一次性原理揭秘
linux·运维·服务器·开发语言·网络·人工智能·学习
兰.lan3 小时前
【黑马ai测试】HTTP协议-抓包工具定位-弱网测试-缺陷介绍
网络·python·网络协议·http