tf.image.stateless_random_crop
Stay organized with collections
Save and categorize content based on your preferences.
Randomly crops a tensor to a given size in a deterministic manner.
tf.image.stateless_random_crop(
value, size, seed, name=None
)
Used in the notebooks
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]
.
Guarantees 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
).
Usage Example:
image = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]
seed = (1, 2)
tf.image.stateless_random_crop(value=image, size=(1, 2, 3), seed=seed)
<tf.Tensor: shape=(1, 2, 3), dtype=int32, numpy=
array([[[1, 2, 3],
[4, 5, 6]]], dtype=int32)>
Args |
value
|
Input tensor to crop.
|
size
|
1-D tensor with size the rank of value .
|
seed
|
A shape [2] Tensor, the seed to the random number generator. Must have
dtype int32 or int64 . (When using XLA, only int32 is allowed.)
|
name
|
A name for this operation (optional).
|
Returns |
A cropped tensor of the same rank as value and shape size .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.image.stateless_random_crop\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/random_crop_ops.py#L85-L135) |\n\nRandomly crops a tensor to a given size in a deterministic manner. \n\n tf.image.stateless_random_crop(\n value, size, seed, name=None\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|--------------------------------------------------------------------------------------|\n| - [Data augmentation](https://www.tensorflow.org/tutorials/images/data_augmentation) |\n\nSlices a shape `size` portion out of `value` at a uniformly chosen offset.\nRequires `value.shape \u003e= size`.\n\nIf a dimension should not be cropped, pass the full size of that dimension.\nFor example, RGB images can be cropped with\n`size = [crop_height, crop_width, 3]`.\n\nGuarantees the same results given the same `seed` independent of how many\ntimes the function is called, and independent of global seed settings (e.g.\n[`tf.random.set_seed`](../../tf/random/set_seed)).\n\n#### Usage Example:\n\n image = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]\n seed = (1, 2)\n tf.image.stateless_random_crop(value=image, size=(1, 2, 3), seed=seed)\n \u003ctf.Tensor: shape=(1, 2, 3), dtype=int32, numpy=\n array([[[1, 2, 3],\n [4, 5, 6]]], dtype=int32)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| `value` | Input tensor to crop. |\n| `size` | 1-D tensor with size the rank of `value`. |\n| `seed` | A shape \\[2\\] Tensor, the seed to the random number generator. Must have dtype `int32` or `int64`. (When using XLA, only `int32` is allowed.) |\n| `name` | A name for this operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A cropped tensor of the same rank as `value` and shape `size`. ||\n\n\u003cbr /\u003e"]]