nvidia.dali.fn.pad#
- nvidia.dali.fn.pad(__input, /, *, align=[], axes=[], axis_names='', bytes_per_sample_hint=[0], fill_value=0.0, preserve=False, seed=-1, shape=[], device=None, name=None)#
Pads all samples with the
fill_value
in the specified axes to match the biggest extent in the batch for those axes or to match the minimum shape specified.Here are a few examples:
1-D samples,
fill_value
= -1,axes
= (0,)
The samples are padded in the first axis to match the extent of the largest sample.
input = [[3, 4, 2, 5, 4], [2, 2], [3, 199, 5]]; output = [[3, 4, 2, 5, 4], [2, 2, -1, -1, -1], [3, 199, 5, -1, -1]]
1-D samples,
fill_value
= -1,axes
= (0,),shape
= (7,)
The samples are padded in the first axis to a minimum extent of 7.
input = [[3, 4, 2, 5, 4], [2, 2], [3, 199, 5], [1, 2, 3, 4, 5, 6, 7, 8]]; output = [[3, 4, 2, 5, 4, -1, -1], [2, 2, -1, -1, -1, -1, -1], [3, 199, 5, -1, -1, -1, -1], [1, 2, 3, 4, 5, 6, 7, 8]]
1-D samples,
fill_value
= -1,axes
= (0,),align
= (4,)
The samples are padded in the first axis to match the extent of the largest sample and the alignment requirements. The output extent is 8, which is a result of rounding up the largest extent (5) to a multiple of alignment (4).
input = [[3, 4, 2, 5, 4], [2, 2], [3, 199, 5]]; output = [[3, 4, 2, 5, 4, -1, -1, -1], [2, 2, -1, -1, -1, -1, -1, -1], [3, 199, 5, -1, -1, -1, -1, -1]]
1-D samples,
fill_value
= -1,axes
= (0,),shape
= (1,),align
= (2,)
The samples are padded in the first axis to match the alignments requirements only. The minimum extent (shape) is set to 1 to avoid any padding other than the necessary for alignment.
input = [[3, 4, 2, 5, 4], [2, 2], [3, 199, 5]]; output = [[3, 4, 2, 5, 4, -1], [2, 2], [3, 199, 5, -1]]
2-D samples,
fill_value
= 42,axes
= (1,)
The samples are padded in the second axis to match the extent of the largest sample and uses a custom fill value 42 instead of the default 0.
input = [[[1, 2, 3, 4], [5, 6, 7, 8]], [[1, 2], [4, 5]]] output = [[[1, 2, 3, 4], [5, 6, 7, 8]], [[1, 2, 42, 42], [4, 5, 42, 42]]]
2-D samples,
fill_value
= 0,axes
= (0, 1),align
= (4, 5)
The samples are padded in the first and second axes to match the alignment requirements of each axis.
input = [[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], [[1, 2], [4, 5]]] output = [[[1, 2, 3, 4, 0], [5, 6, 7, 8, 0], [9, 10, 11, 12, 0], [0, 0, 0, 0, 0]], [[1, 2, 0, 0, 0], [4, 5, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]]
2-D samples,
fill_value
= 0,axes
= (0, 1),align
= (1, 2),shape
= (4, -1)
The samples are padded in the first axis to match a minimum extent of 4, and in the second axis to match the largest sample in the batch and an alignment of 2.
input = [[[1, 2, 3], [4, 5, 6]], [[1, 2], [4, 5], [6, 7]]] output = [[[1, 2, 3, 0], [4, 5, 6, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[1, 2, 0, 0], [4, 5, 0, 0], [6, 7, 0, 0], [0, 0, 0, 0]]]
- Supported backends
‘cpu’
‘gpu’
- Parameters:
__input¶ (TensorList) – Input to the operator.
- Keyword Arguments:
align¶ (int or list of int or TensorList of int, optional, default = []) –
If specified, this argument determines the alignment on the dimensions specified by
axes
oraxis_names
.The extent on
axis = axes[i]
will be adjusted to be a multiple ofalign[i]
.If an integer value is provided, the alignment restrictions are applied to all the padded axes.
To use alignment only, that is without any default or explicit padding behavior, set the minimum
shape
to 1 for the specified axis.axes¶ (int or list of int or TensorList of int, optional, default = []) –
Indices of the axes on which the batch samples will be padded.
Negative values are interpreted as counting dimensions from the back. Valid range:
[-ndim, ndim-1]
, where ndim is the number of dimensions in the input data.The
axis_names
andaxes
arguments are mutually exclusive. Ifaxes
andaxis_names
are empty, or have not been provided, the output will be padded on all of the axes.axis_names¶ (layout str, optional, default = ‘’) –
Names of the axes on which the batch samples will be padded.
The
axis_names
andaxes
arguments are mutually exclusive. Ifaxes
andaxis_names
are empty, or have not been provided, the output will be padded on all of the axes.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.
fill_value¶ (float or TensorList of float, optional, default = 0.0) – The value to pad the batch with.
preserve¶ (bool, optional, default = False) – Prevents the operator from being removed from the graph even if its outputs are not used.
seed¶ (int, optional, default = -1) –
Random seed.
If not provided, it will be populated based on the global seed of the pipeline.
shape¶ (int or list of int or TensorList of int, optional, default = []) –
The extents of the output shape in the axes specified by the
axes
oraxis_names
.Specifying -1 for an axis restores the default behavior of extending the axis to accommodate the aligned size of the largest sample in the batch.
If the provided extent is smaller than the one of the samples, padding will be applied only to match the required alignment. For example, to disable padding in an axis, except for the necessary for alignment, you can specify a value of 1.