【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()
相关推荐
北堂飘霜几秒前
AI 求职工具评测:简小派 vs Jobscan、Teal 与国内同类
人工智能
(●—●)橘子……1 分钟前
力扣344.反转字符串 练习理解
python·学习·算法·leetcode·职场和发展
本妖精不是妖精2 分钟前
在 CentOS 7 上部署 Node.js 18 + Claude Code
linux·python·centos·node.js·claudecode
Vanranrr5 分钟前
Python vs PowerShell:自动化 C++ 配置文件的两种实现方案
c++·python·自动化
糖果罐子♡5 分钟前
在 openEuler 上快速体验 PyTorch 深度学习
人工智能·pytorch·深度学习
周杰伦_Jay5 分钟前
【Conda 完全指南】环境管理+包管理从入门到精通(含实操示例+表格对比)
开发语言·人工智能·微服务·架构·conda
暗碳6 分钟前
ai分析aweme-app.xml,default_config .xml文件
xml·人工智能
凌晨一点的秃头猪7 分钟前
构建视觉词典(visual vocabulary / codebook)
人工智能
PS1232327 分钟前
城市安全建设中的风环境监测解决方案
大数据·人工智能