<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/experimental/nn/util/convolution_util.py#L33-L91) |

Rearrange image blocks into rows.

    tfp.experimental.nn.util.im2row(
        x, block_shape, slice_step=(1, 1), padding='VALID', name=None
    )

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]))`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `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'`). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `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. |

<br />