python - 如何在张量流的占位符中接受张量列表?
问题描述
我想做以下事情:
out = sess.run(operation, feed_dict={x: x_value, , y: y_value})
在模型定义的某个地方,我使用了这个:
x = tf.placeholder(tf.float32, shape=(None, None, 3))
y = tf.placeholder(tf.float32, shape=(None, None, 3))
operation = some_function(x, y)
在哪里x
和y
是图像。如何重写我的代码,以便我可以y
用一个x
. 我想做这样的事情:
x = tf.placeholder(tf.float32, shape=(None, None, 3))
y = []
x = []
for _y in y:
operation = some_function(x, _y)
z.append(operation)
现在我只是这样做:
x = tf.placeholder(tf.float32, shape=(None, None, 3))
y = tf.placeholder(tf.float32, shape=(None, None, None, 3)) #add extra dimension
z = tf.unstack(tf.map_fn(some_function, y))
但问题是当我这样做时,tf.unpack
会抛出一个错误,说它不知道 y 的大小并失败。
这样做可以解决这个问题,我y
用图像总数初始化 0 索引。
x = tf.placeholder(tf.float32, shape=(None, None, 3))
y = tf.placeholder(tf.float32, shape=(2, None, None, 3)) #add extra dimension
z = tf.unstack(tf.map_fn(some_function, y))
我使用以下方法评估值:
y_values = np.stack([y_value1, y_value2])
out = sess.run(operation, feed_dict={x: x_value, , y: y_values })
理想情况下,我希望它是可变的,我不必初始化占位符的值。可以说我希望它对所有不同的y
值进行加权求和。每次只需 1y
或 5y
秒等。
解决方案
推荐阅读
- https - 从 URL 中删除方案是好的做法吗?
- python - 在 tornado 的 ioloop 上使用 asyncio 方法(例如 create_future)
- flutter - Flutter ios release build 找不到快照
- javascript - 如何使用 Javascript API 获得道路元素的形状?
- rpm - RPM GPG key import from an RPM post install script
- java - How to return locked keystore instance after decode from base64?
- xquery - Dynamic Path in XQUERY
- intellij-idea - 如何在颤振中将 dart SDK 更新到最新的稳定版本
- bash - Bash script to install the software
- c# - Getting System.IO.IOException in mscorlib.dll