nvidia.dali.fn.normalize — NVIDIA DALI (original) (raw)

nvidia.dali.fn.normalize(__input, /, *, axes=[], axis_names='', batch=False, bytes_per_sample_hint=[0], ddof=0, dtype=DALIDataType.FLOAT, epsilon=0.0, mean=None, preserve=False, scale=1.0, shift=0.0, stddev=None, device=None, name=None)#

Normalizes the input by removing the mean and dividing by the standard deviation.

The mean and standard deviation can be calculated internally for the specified subset of axes or can be externally provided as the mean and stddev arguments.

The normalization is done following the formula:

out = scale * (in - mean) / stddev + shift

The formula assumes that out and in are equally shaped tensors, but mean and stddev might be either tensors of same shape, scalars, or a mix of these.

Note

The expression follows the numpy broadcasting rules.

Sizes of the non-scalar mean and stddev must have an extent of 1, if given axis is reduced, or match the corresponding extent of the input. A dimension is considered reduced if it is listed in axes or axis_names. If neither the axes nor the axis_namesargument is present, the set of reduced axes is inferred by comparing the input shape to the shape of the mean/stddev arguments, but the set of reduced axes must be the same for all tensors in the batch.

Here are some examples of valid argument combinations:

  1. Per-sample normalization of dimensions 0 and 2:
    axes = 0,2 # optional
    input.shape = [ [480, 640, 3], [1080, 1920, 4] ]
    batch = False
    mean.shape = [ [1, 640, 1], [1, 1920, 1] ]
    stddev = (not supplied)

With these shapes, batch normalization is not possible, because the non-reduced dimension has a different extent across samples.

  1. Batch normalization of dimensions 0 and 1:
    axes = 0,1 # optional
    input.shape = [ [480, 640, 3], [1080, 1920, 3] ]
    batch = True
    mean = (scalar)
    stddev.shape = [ [1, 1, 3] ] ]

For color images, this example normalizes the 3 color channels separately, but across all samples in the batch.

This operator allows sequence inputs and supports volumetric data.

Supported backends

Parameters:

__input (TensorList) – Input to the operator.

Keyword Arguments: