ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more


Rearrange image blocks into rows.

This function can be used to implement 2D convolution as a matmul, e.g.,

tf.nn.conv2d(x, k) = tf.matmul( tf.experimental.nn.util.im2row(x), tf.reshape(k, shape=[-1, out_size])).

x Rank 3 (or more) Tensor representing 2D images.
block_shape Length-2 vector representing the block or "filter" shape.
slice_step Length-2 vector specifying the convolution stride length. Default value: (1, 1).
padding One of 'VALID' or 'SAME' (case insensitive). Default value: 'VALID'.
name Python str used to describe ops created by this function. Default value: None (i.e., 'im2col').

im2row_x batch of matrices representing subblock copies of x. Same batch shape as x but with rightmost shape: batch_shape + [oh * ow, block_shape[0] * block_shape[1] * channels], where oh = (h - block_shape[0] + 1) // slice_step[0] and ow = (w - block_shape[1] + 1) // slice_step[1] when padding = 'VALID' and oh = h and ow = w when padding = 'SAME'.
shape shape Tensor equivalent to: batch_shape + [oh, ow, block_shape[0] * block_shape[1] * channels] where oh, ow are defined as above.