nvidia.dali.experimental.dynamic.random_crop_generator#

nvidia.dali.experimental.dynamic.random_crop_generator(input, /, *, batch_size=None, device=None, num_attempts=None, random_area=None, random_aspect_ratio=None, seed=None, rng=None)#

Produces a cropping window with a randomly selected area and aspect ratio.

Expects a one-dimensional input representing the shape of the input we want to crop (HW or HWC representation).

Produces two outputs, representing the anchor and shape of the cropping window.

The outputs of this operator (anchor and shape) can be fed to fn.slice, fn.decoders.image_slice or any other operator accepting a region of interest. For example:

crop_anchor, crop_shape = fn.random_crop_generator(image_shapes)
images_crop = fn.slice(images, start=crop_anchor, shape=crop_shape, axes=[0, 1])
Supported backends
  • ‘cpu’

Parameters:

input (Tensor/Batch) – Input to the operator.

Keyword Arguments:
  • num_attempts (int, optional, default = 10) – Maximum number of attempts used to choose random area and aspect ratio.

  • random_area (float or list of float, optional, default = [0.08, 1.0]) –

    Range from which to choose random area fraction A.

    The cropped image’s area will be equal to A * original image’s area.

  • random_aspect_ratio (float or list of float, optional, default = [0.75, 1.333333]) – Range from which to choose random aspect ratio (width/height).

  • rng (RNG, optional) – A random number generator instance. Can be obtained by calling nvidia.dali.experimental.dynamic.random.RNG(seed)(). If not provided, the default RNG is used.