nvidia.dali.fn.random_crop_generator

nvidia.dali.fn.random_crop_generator(__input, /, *, bytes_per_sample_hint=[0], num_attempts=10, preserve=False, random_area=[0.08, 1.0], random_aspect_ratio=[0.75, 1.333333], seed=-1, device=None, name=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 (TensorList) – Input to the operator.

Keyword Arguments:
  • bytes_per_sample_hint (int or list of int, optional, default = [0]) –

    Output size hint, in bytes per sample.

    If specified, the operator’s outputs residing in GPU or page-locked host memory will be preallocated to accommodate a batch of samples of this size.

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

  • preserve (bool, optional, default = False) – Prevents the operator from being removed from the graph even if its outputs are not used.

  • 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).

  • seed (int, optional, default = -1) –

    Random seed.

    If not provided, it will be populated based on the global seed of the pipeline.