Using extract_image_patches with multiple channels in Tensorflow

python, tensorflow

Solution

I think, you should try this:

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)

You don't have to specify #channels in ksizes. It will extract patches from each channel and you can reshape it later. Does this helps you ??

Reshaping behavior have to be analysed to check how patches looks.

Problem

I'd like to split my large 1024x1024x3 images into 32x32x3 patches, and hence I thought that `extract_image_patches()` is the right idea: ``` ... 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]) ``` where image_batch is created with `tf.train.shuffle_batch()`. However, this seems to be 'unimplemented' as explained by this error message: ``` 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)]] ``` There is no issue if I read my images as greyscale and use 1 channel, but I want to do my training in full colour. Do I just have to do some reshaping instead, or am I missing something? Python 3.4, TensorFlow 1.1.0

Original source