在Tensorflow中使用具有多个通道的extract_image_patches

时间:2017-05-10 21:15:17

标签: python tensorflow

我想将我的大型1024x1024x3图像拆分为32x32x3补丁,因此我认为extract_image_patches()是正确的想法:

...

patch_size = [1, 32, 32, 3]
patch_batch = tf.extract_image_patches(
    image_batch, patch_size, patch_size, [1, 1, 1, 1], 'VALID')
patch_batch = tf.reshape(patch_batch, [-1, 32, 32, 3])

使用tf.train.shuffle_batch()创建image_batch。然而,这似乎是没有实现的'正如此错误消息所解释的那样:

UnimplementedError (see above for traceback): Only support ksizes across space.
 [[Node: ExtractImagePatches = ExtractImagePatches[T=DT_FLOAT, ksizes=[1, 32, 32, 3], padding="VALID", rates=[1, 1, 1, 1], strides=[1, 32, 32, 3], _device="/job:localhost/replica:0/task:0/cpu:0"](shuffle_batch)]]

如果我将图像作为灰度显示并使用1个通道,则没有问题,但我想以全彩色进行训练。我只需要做一些重塑,或者我错过了什么?

Python 3.4,TensorFlow 1.1.0

1 个答案:

答案 0 :(得分:2)

我想,你应该试试这个:

imgs = np.random.rand(1,1024,1024,3)
patches = tf.extract_image_patches(images=imgs, ksizes=[1, 32, 32, 1], strides=[1, 32, 32, 1], rates=[1, 1, 1, 1], padding='VALID')
patches = tf.reshape(patches,[-1,32,32,3])
val = sess.run(patches)
print val.shape

(1024,32,32,3)

您不必在ksizes中指定#channels。它将从每个通道中提取补丁,您可以稍后重新整形。这对你有帮助吗?

必须分析重塑行为以检查补丁的外观。