Functional API#

Warning

The DALI TorchVision API is an experimental feature and is subject to change.

This page documents the functions currently implemented in the DALI TorchVision API. They are drop-in replacements for their counterparts in torchvision.transforms.v2.functional. For a general introduction, see TorchVision API Overview. To add an operator that is not listed here, see Implementing custom operators. For the operator classes, see Object API.

Every function accepts the additional device argument ("cpu" or "gpu").

Available in the nvidia.dali.experimental.torchvision.v2.functional module.

Geometry functions#

nvidia.dali.experimental.torchvision.v2.functional.resize(
inpt,
size,
interpolation=InterpolationMode.BILINEAR,
max_size=None,
antialias=True,
device='cpu',
)#

Please refer to the Resize operator for more details.

nvidia.dali.experimental.torchvision.v2.functional.center_crop(inpt, output_size, device='cpu')#

Please refer to the CenterCrop operator for more details.

nvidia.dali.experimental.torchvision.v2.functional.crop(inpt, top, left, height, width, device='cpu')#

Please refer to the RandomCrop operator for more details.

nvidia.dali.experimental.torchvision.v2.functional.resized_crop(
inpt,
top,
left,
height,
width,
size,
interpolation=InterpolationMode.BILINEAR,
antialias=True,
device='cpu',
)#

Crop the input at location (top, left) with dimensions (height, width), then resize the crop to the given size.

nvidia.dali.experimental.torchvision.v2.functional.pad(inpt, padding, fill=0, padding_mode='constant', device='cpu')#

Please refer to the Pad operator for more details.

nvidia.dali.experimental.torchvision.v2.functional.horizontal_flip(inpt, device='cpu')#

Horizontally flips the given tensor. Refer to HorizontalFlip for more details.

nvidia.dali.experimental.torchvision.v2.functional.vertical_flip(inpt, device='cpu')#

Vertically flips the given tensor. Refer to VerticalFlip for more details.

Color and filtering functions#

nvidia.dali.experimental.torchvision.v2.functional.rgb_to_grayscale(inpt, num_output_channels=1, device='cpu')#

Please refer to the Grayscale operator for more details.

nvidia.dali.experimental.torchvision.v2.functional.to_grayscale(inpt, num_output_channels=1, device='cpu')#

Please refer to the Grayscale operator for more details.

nvidia.dali.experimental.torchvision.v2.functional.gaussian_blur(inpt, kernel_size, sigma=(0.1, 2.0), device='cpu')#

Please refer to the GaussianBlur operator for more details.

nvidia.dali.experimental.torchvision.v2.functional.normalize(input_data, mean, std, inplace=False, device='cpu')#

Please refer to the Normalize operator for more details.

PIL and tensor conversion functions#

nvidia.dali.experimental.torchvision.v2.functional.pil_to_tensor(inpt)#

Convert a PIL.Image to a uint8 CHW torch.Tensor.

Values are in [0, 255] and the dtype is torch.uint8. No scaling is applied. Mirrors torchvision.transforms.v2.functional.pil_to_tensor.

Parameters:

inpt (PIL.Image) – Input image. Modes L, RGB, and RGBA are supported.

Returns:

CHW tensor of dtype torch.uint8.

Return type:

Tensor

nvidia.dali.experimental.torchvision.v2.functional.to_tensor(inpt)#

Convert a PIL.Image to a float32 CHW torch.Tensor with values in [0, 1].

Mirrors torchvision.transforms.v2.functional.to_tensor (deprecated in TV v2, but kept here for compatibility).

Parameters:

inpt (PIL.Image) – Input image. Modes L, RGB, and RGBA are supported.

Returns:

CHW tensor of dtype torch.float32 with values in [0.0, 1.0].

Return type:

Tensor

nvidia.dali.experimental.torchvision.v2.functional.to_pil_image(inpt, mode=None, input_layout='CHW')#

Convert a CHW torch.Tensor to a PIL.Image.

Mirrors torchvision.transforms.v2.functional.to_pil_image.

Parameters:
  • inpt (Tensor) – CHW tensor. Supported channel counts: 1 (L), 3 (RGB), 4 (RGBA).

  • mode (str or None, optional) – PIL image mode. If None the mode is inferred from the channel count.

Return type:

PIL.Image

Image metadata#

nvidia.dali.experimental.torchvision.v2.functional.get_dimensions(inpt)#

Return the number of channels, height, and width of an image as [channels, height, width].

Mirrors torchvision.transforms.v2.functional.get_dimensions.

Parameters:

inpt (PIL Image or Tensor) – Input image. Tensors are expected in [H, W] or […, C, H, W] layout (leading batch dimensions are ignored).

Returns:

[channels, height, width]

Return type:

List[int]

nvidia.dali.experimental.torchvision.v2.functional.get_image_size(inpt)#

Return the spatial size of an image as [width, height].

Mirrors torchvision.transforms.v2.functional.get_image_size.

Note

This function is provided for compatibility. The torchvision successor get_size returns [height, width] instead.

Parameters:

inpt (PIL Image or TensorLike) – Input image. Tensors are expected in […, H, W] layout (leading channel / batch dimensions are ignored).

Returns:

[width, height]

Return type:

list[int]

nvidia.dali.experimental.torchvision.v2.functional.get_size(inpt)#

Return the spatial size of an image as [height, width].

Mirrors torchvision.transforms.v2.functional.get_size.

Parameters:

inpt (PIL Image or TensorLike) – Input image. Tensors are expected in […, H, W] layout (leading channel / batch dimensions are ignored).

Returns:

[height, width]

Return type:

list[int]