# tf.keras.layers.CenterCrop

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/master/keras/layers/preprocessing/image_preprocessing.py#L124-L192) |

Crop the central portion of the images to target height and width.

Inherits From: [`Layer`](https://www.tensorflow.org/versions/r2.6/api_docs/python/tf/keras/layers/Layer), [`Module`](https://www.tensorflow.org/versions/r2.6/api_docs/python/tf/Module)

#### View aliases


**Main aliases**

[`tf.keras.layers.experimental.preprocessing.CenterCrop`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/CenterCrop)
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.layers.CenterCrop`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/CenterCrop), [`tf.compat.v1.keras.layers.experimental.preprocessing.CenterCrop`](https://www.tensorflow.org/api_docs/python/tf/keras/layers/CenterCrop)

<br />

    tf.keras.layers.CenterCrop(
        height, width, **kwargs
    )

#### Input shape:

3D (unbatched) or 4D (batched) tensor with shape:
`(..., height, width, channels)`, in `"channels_last"` format.

#### Output shape:

3D (unbatched) or 4D (batched) tensor with shape:
`(..., target_height, target_width, channels)`.

If the input height/width is even and the target height/width is odd (or
inversely), the input image is left-padded by 1 pixel.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `height` | Integer, the height of the output shape. |
| `width` | Integer, the width of the output shape. |

<br />