python - 为什么占位符在张量流中不起作用?
问题描述
当我尝试使用 tf.placeholder() 运行一个简单的语句时,我得到以下结果。
X=tf.placeholder(tf.float32,shape=(None,height,width,channels))
Traceback (most recent call last):
File "<ipython-input-6-6f535655ed45>", line 1, in <module>
X=tf.placeholder(tf.float32,shape=(None,height,width,channels))
AttributeError: module 'tensorflow' has no attribute 'placeholder'
在做了一些阅读之后,这似乎与拥有 tensorflow 的第 2 版而不是早期版本有关。但我检查了一下,看来我有 1.14。
pip list
Package Version
---------------------------------- -------------------
tensorboard 1.14.0
tensorboard-plugin-wit 1.6.0.post3
tensorflow 1.14.0
tensorflow-estimator 1.14.0
我对此很陌生,并试图按照书中的教程进行操作,不胜感激。对于上下文,我试图在 Spyder 中运行它作为 Python 3.7 的 Anaconda 发行版的一部分。
编辑:我忘了包括我尝试使用某些版本的 tf.compat.placeholder() 以及。
X = tf.compat.v1.placeholder(tf.float32,shape=(None,height,width,channels))
Traceback (most recent call last):
File "<ipython-input-7-d9a798a5972c>", line 1, in <module>
X = tf.compat.v1.placeholder(tf.float32,shape=(None,height,width,channels))
AttributeError: module 'tensorflow' has no attribute 'compat'
编辑 2:经过更多测试,代码将在 Jupyter 中运行,但不在 Spyder 中,所以我不确定这意味着什么。
解决方案
您可以尝试X = tf.compat.v1.placeholder
按照文档中的建议使用(请参见此处)
推荐阅读
- android - how to get the deleted contact from the android phone and how to restore it
- node.js - NodeJs Mongodb:连接 ECONNREFUSED
:27017 - python - Plotly:如何使用 bx.bar 更改颜色条的标题?
- javascript - JavaScipt:将 HTML 实体作为函数参数传递
- python - 如何获取烧瓶中的最后一个条目
- python-3.x - 将带有参数的python函数应用于apache光束管道
- c# - 如何从管理端获取数据然后在客户端显示?
- python - 让 Python 与外部程序中的工具栏菜单和选项进行交互
- angular - 通过带角度的路线打开离子模态
- java - onClickListener 按钮在片段中不起作用