Note

This page was generated from the docs/torchvision/overview.ipynb Jupyter notebook. You can run it locally or open it in Google Colab, see Running the Examples for more information. To prepare Colab for this exact documentation revision, run this cell before the tutorial:

setup_url = (
    "https://raw.githubusercontent.com/NVIDIA/DALI/"
    "4e6e70d/docs/examples/colab_setup.py"
)
!curl -sSL $setup_url -o colab_setup.py
%run colab_setup.py --ref 4e6e70d

TorchVision API Overview#

Starting from DALI 2.1 a TorchVision-compatible API is available under the experimental namespace. It provides GPU-accelerated drop-in replacements for torchvision.transforms.v2 operators, letting you keep existing TorchVision-style code while transparently offloading work to DALI pipelines.

Two complementary APIs are provided:

Style

Import

Usage

Object-oriented

nvidia.dali.experimental.torchvision

Stateful operator objects chained via Compose

Functional

nvidia.dali.experimental.torchvision.v2.functional

Stateless functions, one call per operation

Importing the TorchVision API#

Import both the object-oriented API (aliased dtv) and the functional API (aliased dtv_fn), alongside the standard TorchVision counterparts for comparison.

[1]:
import torch
import torchvision.transforms.v2 as tv
import torchvision.transforms.v2.functional as tv_fn
from PIL import Image
import numpy as np

# DALI TorchVision API — object-oriented
import nvidia.dali.experimental.torchvision as dtv

# DALI TorchVision API — functional
import nvidia.dali.experimental.torchvision.v2.functional as dtv_fn

print("DALI operators available:", dtv.__all__)
print("DALI functional ops available:", dtv_fn.__all__)
DALI operators available: ['CenterCrop', 'ColorJitter', 'Compose', 'GaussianBlur', 'Grayscale', 'InterpolationMode', 'Normalize', 'Pad', 'PILToTensor', 'RandomApply', 'RandomCrop', 'RandomGrayscale', 'RandomHorizontalFlip', 'RandomResizedCrop', 'RandomVerticalFlip', 'Resize', 'ToPILImage', 'ToPureTensor']
DALI functional ops available: ['center_crop', 'crop', 'gaussian_blur', 'get_dimensions', 'get_image_size', 'get_size', 'horizontal_flip', 'normalize', 'pad', 'pil_to_tensor', 'resize', 'resized_crop', 'rgb_to_grayscale', 'to_grayscale', 'to_pil_image', 'to_tensor', 'vertical_flip']

Available operators#

The DALI TorchVision-compatible API exports a curated subset of torchvision.transforms.v2, in both the object-oriented and the functional style. See the Object API reference and Functional API reference for the list of all currently available operators and their documentation, and Implementing custom operators to extend the API.

Where to go next: