# tf.image.random_crop

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/random_ops.py#L365-L417) |

Randomly crops a tensor to a given size.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.image.random_crop`](https://www.tensorflow.org/api_docs/python/tf/image/random_crop), [`tf.compat.v1.random_crop`](https://www.tensorflow.org/api_docs/python/tf/image/random_crop)

<br />

    tf.image.random_crop(
        value, size, seed=None, name=None
    )

Slices a shape `size` portion out of `value` at a uniformly chosen offset.
Requires `value.shape >= size`.

If a dimension should not be cropped, pass the full size of that dimension.
For example, RGB images can be cropped with
`size = [crop_height, crop_width, 3]`.

#### Example usage:

    image = [[1, 2, 3], [4, 5, 6]]
    result = tf.image.random_crop(value=image, size=(1, 3))
    result.shape.as_list()
    [1, 3]

For producing deterministic results given a `seed` value, use
[`tf.image.stateless_random_crop`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/image/stateless_random_crop). Unlike using the `seed` param with
`tf.image.random_*` ops, `tf.image.stateless_random_*` ops guarantee the same
results given the same seed independent of how many times the function is
called, and independent of global seed settings (e.g. tf.random.set_seed).

<br />

<br />

<br />

| ## Args ||
|---|---|
| `value` | Input tensor to crop. |
| `size` | 1-D tensor with size the rank of `value`. |
| `seed` | Python integer. Used to create a random seed. See [`tf.random.set_seed`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/random/set_seed) for behavior. |
| `name` | A name for this operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A cropped tensor of the same rank as `value` and shape `size`. ||

<br />