【发布时间】:2017-02-20 21:33:14
【问题描述】:
我有一个函数get_image(...) 对我的输入图像执行预处理。我在这样的列表中收集属于同一批次的所有图像:
batch = [get_image(file_path) for file_path in batch_files]
现在我想将此列表转换为一个张量,其中第一个维度是批量大小维度,这样我就可以将它提供给我的网络的输入占位符。
_ = self.sess.run([loss],feed_dict={ input_placeholder: batch })
知道我该怎么做吗?
batch_concat = tf.placeholder(shape=[None] + self.image_shape, dtype=tf.float32)
for i in xrange(0,self.batch_size):
if i == 0:
tmp_batch = tf.expand_dims(batch[i], 0)
batch_concat = tmp_batch
else:
tmp_batch = tf.expand_dims(batch[i], 0)
batch_concat = tf.concat(0, [batch_concat, tmp_batch])
当我尝试连接所有张量时,出现以下错误:
TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, or numpy ndarrays.
那么在将张量输入网络之前将其转换回 numpy 数组就足够了?
【问题讨论】:
-
不清楚你想在这里做什么。为什么不将包含图像的 python 列表作为 input_batch 传递? tensorflow 会为你转换它
-
我想使用tf提供的预处理功能。否则我将不得不在 python 中重写所有内容......
标签: tensorflow