# tf.contrib.layers.max_pool2d

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/layers/python/layers/layers.py#L2371-L2418) |

Adds a 2D Max Pooling op.

    tf.contrib.layers.max_pool2d(
        inputs, kernel_size, stride=2, padding='VALID', data_format=DATA_FORMAT_NHWC,
        outputs_collections=None, scope=None
    )

It is assumed that the pooling is done per image but not in batch or channels.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `inputs` | A 4-D tensor of shape `[batch_size, height, width, channels]` if `data_format` is `NHWC`, and `[batch_size, channels, height, width]` if `data_format` is `NCHW`. |
| `kernel_size` | A list of length 2: \[kernel_height, kernel_width\] of the pooling kernel over which the op is computed. Can be an int if both values are the same. |
| `stride` | A list of length 2: \[stride_height, stride_width\]. Can be an int if both strides are the same. Note that presently both strides must have the same value. |
| `padding` | The padding method, either 'VALID' or 'SAME'. |
| `data_format` | A string. `NHWC` (default) and `NCHW` are supported. |
| `outputs_collections` | The collections to which the outputs are added. |
| `scope` | Optional scope for name_scope. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` representing the results of the pooling operation. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `data_format` is neither `NHWC` nor `NCHW`. |
| `ValueError` | If 'kernel_size' is not a 2-D list |

<br />