nvidia.dali.fn.experimental.tensor_resize

nvidia.dali.fn.experimental.tensor_resize(__input, /, *, alignment=[0.5], antialias=True, axes=None, axis_names=None, bytes_per_sample_hint=[0], dtype=None, interp_type=DALIInterpType.INTERP_LINEAR, mag_filter=DALIInterpType.INTERP_LINEAR, max_size=None, min_filter=DALIInterpType.INTERP_LINEAR, minibatch_size=32, mode='default', preserve=False, roi_end=None, roi_relative=False, roi_start=None, scales=None, seed=-1, size_rounding='round', sizes=None, subpixel_scale=True, temp_buffer_hint=0, device=None, name=None)

Resize tensors.

This operator allows sequence inputs and supports volumetric data.

Supported backends
  • ‘cpu’

  • ‘gpu’

Parameters:

__input (TensorList) – Input to the operator.

Keyword Arguments:
  • alignment (float or list of float or TensorList of float, optional, default = [0.5]) –

    Determines the position of the ROI when using scales (provided or calculated).

    The real output size must be integral and may differ from “ideal” output size calculated as input (or ROI) size multiplied by the scale factor. In that case, the output size is rounded (according to size_rounding policy) and the input ROI needs to be adjusted to maintain the scale factor. This parameter defines which relative point of the ROI should retain its position in the output.

    This point is calculated as center = (1 - alignment) * roi_start + alignment * roi_end. Alignment 0.0 denotes alignment with the start of the ROI, 0.5 with the center of the region, and 1.0 with the end. Note that when ROI is not specified, roi_start=0 and roi_end=input_size is assumed.

    When using 0.5 (default), the resize operation has flip invariant properties (flipping after resizing is mathematically equivalent to resizing after flipping).

    The value of this argument contains as many elements as dimensions provided for sizes/scales. If only one value is provided, it is applied to all dimensions.

  • antialias (bool, optional, default = True) –

    If enabled, it applies an antialiasing filter when scaling down.

    Note

    Nearest neighbor interpolation does not support antialiasing.

  • axes (int or list of int, optional) –

    Indices of dimensions that sizes, scales, max_size, roi_start, roi_end refer to.

    Accepted range is [-ndim, ndim-1]. Negative indices are counted from the back.

    By default, all dimensions are assumed. The axis_names and axes arguments are mutually exclusive.

  • axis_names (layout str, optional) –

    Names of the axes that sizes, scales, max_size, roi_start, roi_end refer to.

    By default, all dimensions are assumed. The axis_names and axes arguments are mutually exclusive.

  • 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.

  • dtype (nvidia.dali.types.DALIDataType, optional) –

    Output data type.

    Must be same as input type or float. If not set, input type is used.

  • interp_type (nvidia.dali.types.DALIInterpType or TensorList of nvidia.dali.types.DALIInterpType, optional, default = DALIInterpType.INTERP_LINEAR) –

    Type of interpolation to be used.

    Use min_filter and mag_filter to specify different filtering for downscaling and upscaling.

    Note

    Usage of INTERP_TRIANGULAR is now deprecated and it should be replaced by a combination of

    INTERP_LINEAR with antialias enabled.

  • mag_filter (nvidia.dali.types.DALIInterpType or TensorList of nvidia.dali.types.DALIInterpType, optional, default = DALIInterpType.INTERP_LINEAR) – Filter used when scaling up.

  • max_size (float or list of float, optional) –

    Limit of the output size.

    When the operator is configured to keep aspect ratio and only the smaller dimension is specified, the other(s) can grow very large. This can happen when using resize_shorter argument or “not_smaller” mode or when some extents are left unspecified.

    This parameter puts a limit to how big the output can become. This value can be specified per-axis or uniformly for all axes.

    Note

    When used with “not_smaller” mode or resize_shorter argument, max_size takes precedence and the aspect ratio is kept - for example, resizing with mode="not_smaller", size=800, max_size=1400 an image of size 1200x600 would be resized to 1400x700.

  • min_filter (nvidia.dali.types.DALIInterpType or TensorList of nvidia.dali.types.DALIInterpType, optional, default = DALIInterpType.INTERP_LINEAR) – Filter used when scaling down.

  • minibatch_size (int, optional, default = 32) – Maximum number of images that are processed in a kernel call.

  • mode (str, optional, default = ‘default’) –

    Resize mode.

    Here is a list of supported modes:

    • "default" - image is resized to the specified size.
      Missing extents are scaled with the average scale of the provided ones.
    • "stretch" - image is resized to the specified size.
      Missing extents are not scaled at all.
    • "not_larger" - image is resized, keeping the aspect ratio, so that no extent of the output image exceeds the specified size.
      For example, a 1280x720, with a desired output size of 640x480, actually produces a 640x360 output.
    • "not_smaller" - image is resized, keeping the aspect ratio, so that no extent of the output image is smaller than specified.
      For example, a 640x480 image with a desired output size of 1920x1080, actually produces a 1920x1440 output.

      This argument is mutually exclusive with resize_longer and resize_shorter

  • preserve (bool, optional, default = False) – Prevents the operator from being removed from the graph even if its outputs are not used.

  • roi_end (float or list of float or TensorList of float, optional) –

    End of the input region of interest (ROI).

    Must be specified together with roi_start. The coordinates follow the tensor shape order, which is the same as size. The coordinates can be either absolute (in pixels, which is the default) or relative (0..1), depending on the value of relative_roi argument. If the ROI origin is greater than the ROI end in any dimension, the region is flipped in that dimension.

  • roi_relative (bool, optional, default = False) – If true, ROI coordinates are relative to the input size, where 0 denotes top/left and 1 denotes bottom/right

  • roi_start (float or list of float or TensorList of float, optional) –

    Origin of the input region of interest (ROI).

    Must be specified together with roi_end. The coordinates follow the tensor shape order, which is the same as size. The coordinates can be either absolute (in pixels, which is the default) or relative (0..1), depending on the value of relative_roi argument. If the ROI origin is greater than the ROI end in any dimension, the region is flipped in that dimension.

  • scales (float or list of float or TensorList of float, optional) –

    Scale factors.

    The resulting output size is calculated as out_size = size_rounding(scale_factor * original_size). See size_rounding for a list of supported rounding policies.

    When axes is provided, the scale factor values refer to the axes specified. Note: Arguments sizes and scales are mutually exclusive.

  • seed (int, optional, default = -1) –

    Random seed.

    If not provided, it will be populated based on the global seed of the pipeline.

  • size_rounding (str, optional, default = ‘round’) –

    Determines the rounding policy when using scales.

    Possible values are: * | "round" - Rounds the resulting size to the nearest integer value, with halfway cases rounded away from zero. * | "truncate" - Discards the fractional part of the resulting size. * | "ceil" - Rounds up the resulting size to the next integer value.

  • sizes (float or list of float or TensorList of float, optional) –

    Output sizes.

    When axes is provided, the size values refer to the axes specified. Note: Arguments sizes and scales are mutually exclusive.

  • subpixel_scale (bool, optional, default = True) –

    If True, fractional sizes, directly specified or calculated, will cause the input ROI to be adjusted to keep the scale factor.

    Otherwise, the scale factor will be adjusted so that the source image maps to the rounded output size.

  • temp_buffer_hint (int, optional, default = 0) –

    Initial size in bytes, of a temporary buffer for resampling.

    Note

    This argument is ignored for the CPU variant.