Implementation:NVIDIA DALI Fn Resize Linear
| Knowledge Sources | |
|---|---|
| Domains | Image_Processing, GPU_Computing, Image_Transformation |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete operator for resizing image tensors to a target spatial resolution using configurable interpolation, provided by the nvidia.dali.fn module.
Description
fn.resize resamples image tensors from their original [H, W, C] dimensions to a specified target (height, width) using a configurable interpolation kernel. When operating on GPU-resident tensors (the typical case after mixed-device decoding), the entire resize computation runs on the GPU with no host-device data transfer.
Key behaviors:
- size accepts a (height, width) tuple specifying the target output dimensions.
- interp_type=types.INTERP_LINEAR selects bilinear interpolation, computing each output pixel as a weighted average of the four nearest source pixels.
- antialias=False disables the low-pass pre-filter that prevents aliasing during downsampling, trading visual quality for speed.
- The operator preserves the input data type (uint8 in, uint8 out) and channel count.
- Both upsampling and downsampling are supported within the same batch; each sample is resized independently.
Usage
Place fn.resize after the decode operator and before normalization or augmentation operators. Specify the target dimensions via the size parameter as a (height, width) tuple. Select the interpolation method via interp_type based on the quality/speed trade-off required by the application.
Code Reference
Source Location
- Repository: NVIDIA DALI
- File: docs/examples/zoo/images/decode_and_transform_pytorch.py (lines 85-90)
Signature
fn.resize(
decoded,
size=img_hw,
interp_type=types.INTERP_LINEAR,
antialias=False,
)
Import
import nvidia.dali.fn as fn
import nvidia.dali.types as types
# or
from nvidia.dali import fn, types
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| decoded | DataNode | Yes | Input image tensor with layout [H, W, C], typically GPU-resident after mixed-device decoding |
| size | tuple(int, int) or list | Yes | Target output dimensions as (height, width) |
| interp_type | types.DALIInterpType | No | Interpolation method: types.INTERP_LINEAR (bilinear), types.INTERP_NN (nearest neighbor), types.INTERP_CUBIC, types.INTERP_LANCZOS3, types.INTERP_TRIANGULAR. Default: types.INTERP_LINEAR |
| antialias | bool | No | Enable low-pass pre-filter to reduce aliasing when downsampling. Default: True |
Outputs
| Name | Type | Description |
|---|---|---|
| resized | DataNode (GPU) | Resized image tensor with layout [target_h, target_w, C] and same dtype as input, residing in GPU memory |
Usage Examples
Example: Resize After Decode in PyTorch Integration Pipeline
from nvidia.dali import pipeline_def, fn, types
@pipeline_def
def image_pipe(img_hw=(320, 200)):
encoded_images = fn.external_source(name="images", no_copy=True)
decoded = fn.decoders.image(
encoded_images,
device="mixed",
output_type=types.RGB,
use_fast_idct=False,
jpeg_fancy_upsampling=True,
)
images = fn.resize(
decoded,
size=img_hw,
interp_type=types.INTERP_LINEAR,
antialias=False,
)
return images
pipe = image_pipe(batch_size=8, num_threads=4, device_id=0)
pipe.build()
Example: Resize with Custom Dimensions
from nvidia.dali import pipeline_def, fn, types
@pipeline_def(batch_size=16, num_threads=4, device_id=0)
def resize_pipe():
data = fn.external_source(name="input_images", no_copy=True)
decoded = fn.decoders.image(data, device="mixed", output_type=types.RGB)
# Resize to 224x224 for ImageNet-style models
resized = fn.resize(
decoded,
size=(224, 224),
interp_type=types.INTERP_LINEAR,
antialias=True,
)
return resized