pub struct IResizeLayer { /* private fields */ }Expand description
IResizeLayer
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:
- InterpolationMode::kNEAREST - resizes last
mdimensions of N-D, where 0 < m <= min(8, N) and N > 0 - InterpolationMode::kLINEAR - resizes last
mdimensions of N-D, where 0 < m <= min(3, N) and N > 0
Default resize mode is InterpolationMode::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 InterpolationMode 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:
- In kNEAREST mode:
- (ResizeCoordinateTransformation::kASYMMETRIC, ResizeSelector::kFORMULA, ResizeRoundMode::kFLOOR)
- (ResizeCoordinateTransformation::kHALF_PIXEL, ResizeSelector::kFORMULA, ResizeRoundMode::kHALF_DOWN)
- (ResizeCoordinateTransformation::kHALF_PIXEL, ResizeSelector::kFORMULA, ResizeRoundMode::kHALF_UP)
- In kLINEAR mode:
- (ResizeCoordinateTransformation::kHALF_PIXEL, ResizeSelector::kFORMULA)
- (ResizeCoordinateTransformation::kHALF_PIXEL, ResizeSelector::kUPPER)
Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
Implementations§
Source§impl IResizeLayer
impl IResizeLayer
Sourcepub fn setOutputDimensions(self: Pin<&mut IResizeLayer>, dimensions: &Dims64)
pub fn setOutputDimensions(self: Pin<&mut IResizeLayer>, dimensions: &Dims64)
Set the output dimensions.
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 [setScales]
See [getOutputDimensions]
Sourcepub fn getOutputDimensions(self: &IResizeLayer) -> Dims64
pub fn getOutputDimensions(self: &IResizeLayer) -> Dims64
Get the output dimensions.
The output dimensions.
Sourcepub unsafe fn setScales(
self: Pin<&mut IResizeLayer>,
scales: *const f32,
nbScales: i32,
)
pub unsafe fn setScales( self: Pin<&mut IResizeLayer>, scales: *const f32, nbScales: i32, )
Set the resize scales.
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:
- nbScales has to be exactly 4.
- the first two elements in scales need to be exactly 1 (for unchanged batch and channel dimensions).
- 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 [setOutputDimensions]
See [getScales]
Sourcepub unsafe fn getScales(self: &IResizeLayer, size: i32, scales: *mut f32) -> i32
pub unsafe fn getScales(self: &IResizeLayer, size: i32, scales: *mut f32) -> i32
Copies resize scales to scales[0, …, nbScales-1], where nbScales is the number of scales that were set.
-
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.
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.
Sourcepub fn setResizeMode(
self: Pin<&mut IResizeLayer>,
interpolationMode: InterpolationMode,
)
pub fn setResizeMode( self: Pin<&mut IResizeLayer>, interpolationMode: InterpolationMode, )
Set resize mode for an input tensor.
Supported resize modes are Nearest Neighbor and Linear.
Sourcepub fn getResizeMode(self: &IResizeLayer) -> InterpolationMode
pub fn getResizeMode(self: &IResizeLayer) -> InterpolationMode
Get resize mode for an input tensor.
The resize mode.
Sourcepub fn setCoordinateTransformation(
self: Pin<&mut IResizeLayer>,
coordTransform: ResizeCoordinateTransformation,
)
pub fn setCoordinateTransformation( self: Pin<&mut IResizeLayer>, coordTransform: ResizeCoordinateTransformation, )
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.
Sourcepub fn getCoordinateTransformation(
self: &IResizeLayer,
) -> ResizeCoordinateTransformation
pub fn getCoordinateTransformation( self: &IResizeLayer, ) -> ResizeCoordinateTransformation
Get coordinate transformation function.
The coordinate transformation function.
Sourcepub fn setSelectorForSinglePixel(
self: Pin<&mut IResizeLayer>,
selector: ResizeSelector,
)
pub fn setSelectorForSinglePixel( self: Pin<&mut IResizeLayer>, selector: ResizeSelector, )
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 ResizeSelector
Sourcepub fn getSelectorForSinglePixel(self: &IResizeLayer) -> ResizeSelector
pub fn getSelectorForSinglePixel(self: &IResizeLayer) -> ResizeSelector
Get the coordinate selector function when resized to single pixel.
The selector function.
Sourcepub fn setNearestRounding(self: Pin<&mut IResizeLayer>, value: ResizeRoundMode)
pub fn setNearestRounding(self: Pin<&mut IResizeLayer>, value: ResizeRoundMode)
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 ResizeRoundMode
Sourcepub fn getNearestRounding(self: &IResizeLayer) -> ResizeRoundMode
pub fn getNearestRounding(self: &IResizeLayer) -> ResizeRoundMode
Get rounding mode for nearest neighbor resize.
The rounding mode.
Sourcepub fn setCubicCoeff(self: Pin<&mut IResizeLayer>, A: f32)
pub fn setCubicCoeff(self: Pin<&mut IResizeLayer>, A: f32)
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.
Sourcepub fn getCubicCoeff(self: &IResizeLayer) -> f32
pub fn getCubicCoeff(self: &IResizeLayer) -> f32
Get the coefficient ‘A’ used in cubic interpolation.
See [setCubicCoeff()]
Sourcepub fn setExcludeOutside(self: Pin<&mut IResizeLayer>, excludeFlag: bool)
pub fn setExcludeOutside(self: Pin<&mut IResizeLayer>, excludeFlag: bool)
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.
Sourcepub fn getExcludeOutside(self: &IResizeLayer) -> bool
pub fn getExcludeOutside(self: &IResizeLayer) -> bool
Get the state for excluding outside pixels.
See [setExcludeOutside()]