TensorRT 8.5.3
nvinfer1::IResizeLayer Class Reference

A resize layer in a network definition. More...

#include <NvInfer.h>

Inheritance diagram for nvinfer1::IResizeLayer:
nvinfer1::ILayer nvinfer1::INoCopy

Public Member Functions

void setOutputDimensions (Dims dimensions) noexcept
 Set the output dimensions. More...
 
Dims getOutputDimensions () const noexcept
 Get the output dimensions. More...
 
void setScales (float const *scales, int32_t nbScales) noexcept
 Set the resize scales. More...
 
int32_t getScales (int32_t size, float *scales) const noexcept
 Copies resize scales to scales[0, ..., nbScales-1], where nbScales is the number of scales that were set. More...
 
void setResizeMode (ResizeMode resizeMode) noexcept
 Set resize mode for an input tensor. More...
 
ResizeMode getResizeMode () const noexcept
 Get resize mode for an input tensor. More...
 
TRT_DEPRECATED void setAlignCorners (bool alignCorners) noexcept
 Set whether to align corners while resizing. More...
 
TRT_DEPRECATED bool getAlignCorners () const noexcept
 True if align corners has been set. More...
 
void setCoordinateTransformation (ResizeCoordinateTransformation coordTransform) noexcept
 Set coordinate transformation function. More...
 
ResizeCoordinateTransformation getCoordinateTransformation () const noexcept
 Get coordinate transformation function. More...
 
void setSelectorForSinglePixel (ResizeSelector selector) noexcept
 Set coordinate selector function when resized to single pixel. More...
 
ResizeSelector getSelectorForSinglePixel () const noexcept
 Get the coordinate selector function when resized to single pixel. More...
 
void setNearestRounding (ResizeRoundMode value) noexcept
 Set rounding mode for nearest neighbor resize. More...
 
ResizeRoundMode getNearestRounding () const noexcept
 Get rounding mode for nearest neighbor resize. More...
 
void setCubicCoeff (float A) noexcept
 Set the coefficient 'A' used in cubic interpolation. More...
 
float getCubicCoeff () const noexcept
 Get the coefficient 'A' used in cubic interpolation. More...
 
void setExcludeOutside (bool excludeFlag) noexcept
 Set the state for excluding outside pixels. More...
 
bool getExcludeOutside () const noexcept
 Get the state for excluding outside pixels. More...
 
void setInput (int32_t index, ITensor &tensor) noexcept
 Append or replace an input of this layer with a specific tensor. More...
 
- Public Member Functions inherited from nvinfer1::ILayer
LayerType getType () const noexcept
 Return the type of a layer. More...
 
void setName (char const *name) noexcept
 Set the name of a layer. More...
 
char const * getName () const noexcept
 Return the name of a layer. More...
 
int32_t getNbInputs () const noexcept
 Get the number of inputs of a layer. More...
 
ITensorgetInput (int32_t index) const noexcept
 Get the layer input corresponding to the given index. More...
 
int32_t getNbOutputs () const noexcept
 Get the number of outputs of a layer. More...
 
ITensorgetOutput (int32_t index) const noexcept
 Get the layer output corresponding to the given index. More...
 
void setInput (int32_t index, ITensor &tensor) noexcept
 Replace an input of this layer with a specific tensor. More...
 
void setPrecision (DataType dataType) noexcept
 Set the computational precision of this layer. More...
 
DataType getPrecision () const noexcept
 get the computational precision of this layer More...
 
bool precisionIsSet () const noexcept
 whether the computational precision has been set for this layer More...
 
void resetPrecision () noexcept
 reset the computational precision for this layer More...
 
void setOutputType (int32_t index, DataType dataType) noexcept
 Set the output type of this layer. More...
 
DataType getOutputType (int32_t index) const noexcept
 get the output type of this layer More...
 
bool outputTypeIsSet (int32_t index) const noexcept
 whether the output type has been set for this layer More...
 
void resetOutputType (int32_t index) noexcept
 reset the output type for this layer More...
 

Protected Member Functions

virtual ~IResizeLayer () noexcept=default
 
- Protected Member Functions inherited from nvinfer1::ILayer
virtual ~ILayer () noexcept=default
 
- Protected Member Functions inherited from nvinfer1::INoCopy
 INoCopy ()=default
 
virtual ~INoCopy ()=default
 
 INoCopy (INoCopy const &other)=delete
 
INoCopyoperator= (INoCopy const &other)=delete
 
 INoCopy (INoCopy &&other)=delete
 
INoCopyoperator= (INoCopy &&other)=delete
 

Protected Attributes

apiv::VResizeLayer * mImpl
 
- Protected Attributes inherited from nvinfer1::ILayer
apiv::VLayer * mLayer
 

Detailed Description

A resize layer in a network definition.

Resize layer can be used for resizing a N-D tensor.

Resize layer currently supports the following configurations:

  • ResizeMode::kNEAREST - resizes innermost m dimensions of N-D, where 0 < m <= min(8, N) and N > 0
  • ResizeMode::kLINEAR - resizes innermost m dimensions of N-D, where 0 < m <= min(3, N) and N > 0

Default resize mode is ResizeMode::kNEAREST.

The coordinates in the output tensor are mapped to coordinates in the input tensor using a function set by calling setCoordinateTransformation(). The default for all ResizeMode settings (nearest, linear, bilinear, etc.) is ResizeCoordinateTransformation::kASYMMETRIC.

The resize layer provides two ways to resize tensor dimensions.

  • Set output dimensions directly. It can be done for static as well as dynamic resize layer. Static resize layer requires output dimensions to be known at build-time. Dynamic resize layer requires output dimensions to be set as one of the input tensors.
  • Set scales for resize. Each output dimension is calculated as floor(input dimension * scale). Only static resize layer allows setting scales where the scales are known at build-time.

If executing this layer on DLA, the following combinations of parameters are supported:

Warning
Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.

Constructor & Destructor Documentation

◆ ~IResizeLayer()

virtual nvinfer1::IResizeLayer::~IResizeLayer ( )
protectedvirtualdefaultnoexcept

Member Function Documentation

◆ getAlignCorners()

TRT_DEPRECATED bool nvinfer1::IResizeLayer::getAlignCorners ( ) const
inlinenoexcept

True if align corners has been set.

Returns
True if align corners has been set, false otherwise.
Deprecated:
Deprecated in TensorRT 8.0. Superseded by IResizeLayer::getCoordinateTransformation().

◆ getCoordinateTransformation()

ResizeCoordinateTransformation nvinfer1::IResizeLayer::getCoordinateTransformation ( ) const
inlinenoexcept

Get coordinate transformation function.

Returns
The coordinate transformation function.

◆ getCubicCoeff()

float nvinfer1::IResizeLayer::getCubicCoeff ( ) const
inlinenoexcept

Get the coefficient 'A' used in cubic interpolation.

See also
setCubicCoeff()

◆ getExcludeOutside()

bool nvinfer1::IResizeLayer::getExcludeOutside ( ) const
inlinenoexcept

Get the state for excluding outside pixels.

See also
setExcludeOutside()

◆ getNearestRounding()

ResizeRoundMode nvinfer1::IResizeLayer::getNearestRounding ( ) const
inlinenoexcept

Get rounding mode for nearest neighbor resize.

Returns
The rounding mode.

◆ getOutputDimensions()

Dims nvinfer1::IResizeLayer::getOutputDimensions ( ) const
inlinenoexcept

Get the output dimensions.

Returns
The output dimensions.

◆ getResizeMode()

ResizeMode nvinfer1::IResizeLayer::getResizeMode ( ) const
inlinenoexcept

Get resize mode for an input tensor.

Returns
The resize mode.

◆ getScales()

int32_t nvinfer1::IResizeLayer::getScales ( int32_t  size,
float *  scales 
) const
inlinenoexcept

Copies resize scales to scales[0, ..., nbScales-1], where nbScales is the number of scales that were set.

Parameters
sizeThe number of scales to get. If size != nbScales, no scales will be copied.
scalesPointer to where to copy the scales. Scales will be copied only if size == nbScales and scales != nullptr.

In case the size is not known consider using size = 0 and scales = nullptr. This method will return the number of resize scales.

Returns
The number of resize scales i.e. nbScales if scales were set. Return -1 in case no scales were set or resize layer is used in dynamic mode.

◆ getSelectorForSinglePixel()

ResizeSelector nvinfer1::IResizeLayer::getSelectorForSinglePixel ( ) const
inlinenoexcept

Get the coordinate selector function when resized to single pixel.

Returns
The selector function.

◆ setAlignCorners()

TRT_DEPRECATED void nvinfer1::IResizeLayer::setAlignCorners ( bool  alignCorners)
inlinenoexcept

Set whether to align corners while resizing.

If true, the centers of the 4 corner pixels of both input and output tensors are aligned i.e. preserves the values of corner pixels.

Default: false.

Deprecated:
Deprecated in TensorRT 8.0. Superseded by IResizeLayer::setCoordinateTransformation().

◆ setCoordinateTransformation()

void nvinfer1::IResizeLayer::setCoordinateTransformation ( ResizeCoordinateTransformation  coordTransform)
inlinenoexcept

Set coordinate transformation function.

The function maps a coordinate in the output tensor to a coordinate in the input tensor.

Default function is ResizeCoordinateTransformation::kASYMMETRIC.

See also
ResizeCoordinateTransformation

◆ setCubicCoeff()

void nvinfer1::IResizeLayer::setCubicCoeff ( float  A)
inlinenoexcept

Set the coefficient 'A' used in cubic interpolation.

Cubic uses the coefficient 'A' to calculate the weight of input pixels:

x := The relative distance between the sampled pixels and the input coordinates.

weight(x) := for |x| <= 1, ((A + 2) * x - (A + 3)) * x * x + 1,
             for 1 < |x| < 2, ((A * x - 5 * A) * x + 8 * A) * x - 4 * A,
             others 0;

This attribute is valid only if "resize mode" is "cubic".

The default value is -0.75.

◆ setExcludeOutside()

void nvinfer1::IResizeLayer::setExcludeOutside ( bool  excludeFlag)
inlinenoexcept

Set the state for excluding outside pixels.

If set to true, the weight of sampling locations outside the input tensor will be set to false, and the weight will be renormalized so that their sum is 1.0.

The default value is false.

◆ setInput()

void nvinfer1::ILayer::setInput ( int32_t  index,
ITensor tensor 
)
inlinenoexcept

Append or replace an input of this layer with a specific tensor.

Parameters
indexthe index of the input to modify.
tensorthe new input tensor.

Sets the input tensor for the given index. The index must be 0 for a static resize layer. A static resize layer is converted to a dynamic resize layer by calling setInput with an index 1. A dynamic resize layer cannot be converted back to a static resize layer.

For a dynamic resize layer, the values 0 and 1 are valid. The indices in the dynamic case are as follows:

  • 0: Execution tensor to be resized.
  • 1: The output dimensions, as a 1D Int32 shape tensor.

If this function is called with the value 1, then the function getNbInputs() changes from returning 1 to 2.

◆ setNearestRounding()

void nvinfer1::IResizeLayer::setNearestRounding ( ResizeRoundMode  value)
inlinenoexcept

Set rounding mode for nearest neighbor resize.

This value is used for nearest neighbor interpolation rounding. It is applied after coordinate transformation.

Default is kFLOOR.

See also
ResizeRoundMode

◆ setOutputDimensions()

void nvinfer1::IResizeLayer::setOutputDimensions ( Dims  dimensions)
inlinenoexcept

Set the output dimensions.

Parameters
dimensionsThe output dimensions. Number of output dimensions must be the same as the number of input dimensions.

If executing this layer on DLA, setOutputDimensions() is not supported.

If there is a second input, i.e. resize layer is dynamic, calling setOutputDimensions() is an error and does not update the dimensions.

Output dimensions can be specified directly, or via scale factors relative to input dimensions. Scales for resize can be provided using setScales().

See also
setScales
getOutputDimensions

◆ setResizeMode()

void nvinfer1::IResizeLayer::setResizeMode ( ResizeMode  resizeMode)
inlinenoexcept

Set resize mode for an input tensor.

Supported resize modes are Nearest Neighbor and Linear.

See also
ResizeMode

◆ setScales()

void nvinfer1::IResizeLayer::setScales ( float const *  scales,
int32_t  nbScales 
)
inlinenoexcept

Set the resize scales.

Parameters
scalesAn array of resize scales.
nbScalesNumber of scales. Number of scales must be equal to the number of input dimensions.

If executing this layer on DLA, there are three restrictions: 1) nbScales has to be exactly 4. 2) the first two elements in scales need to be exactly 1 (for unchanged batch and channel dimensions). 3) The last two elements in scales, representing the scale values along height and width dimensions, respectively, need to be integer values in the range of [1, 32] for kNEAREST mode and [1, 4] for kLINEAR. Example of DLA-supported scales: {1, 1, 2, 2}.

If there is a second input, i.e. resize layer is dynamic, calling setScales() is an error and does not update the scales.

Output dimensions are calculated as follows: outputDims[i] = floor(inputDims[i] * scales[i])

Output dimensions can be specified directly, or via scale factors relative to input dimensions. Output dimensions can be provided directly using setOutputDimensions().

See also
setOutputDimensions
getScales

◆ setSelectorForSinglePixel()

void nvinfer1::IResizeLayer::setSelectorForSinglePixel ( ResizeSelector  selector)
inlinenoexcept

Set coordinate selector function when resized to single pixel.

When resize to single pixel image, use this function to decide how to map the coordinate in the original image.

Default is ResizeSelector::kFORMULA.

See also
ResizeSelector

Member Data Documentation

◆ mImpl

apiv::VResizeLayer* nvinfer1::IResizeLayer::mImpl
protected

The documentation for this class was generated from the following file: