我有一个功能get_image(...)
,它对我的输入图像执行预处理。我收集的名单属于同一批次的所有图像是这样的:Tensorflow:从图像张量列表中创建批量
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会将它转换为你 – fabrizioM
我想使用tf提供的预处理功能。否则,我将不得不重写Python中的所有内容... – mcExchange