Skip to main content

IResizeLayer

Struct IResizeLayer 

Source
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 m dimensions of N-D, where 0 < m <= min(8, N) and N > 0
  • InterpolationMode::kLINEAR - resizes last m dimensions 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

Source

pub fn setOutputDimensions(self: Pin<&mut IResizeLayer>, dimensions: &Dims64)

Set the output dimensions.

  • dimensions The 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]

Source

pub fn getOutputDimensions(self: &IResizeLayer) -> Dims64

Get the output dimensions.

The output dimensions.

Source

pub unsafe fn setScales( self: Pin<&mut IResizeLayer>, scales: *const f32, nbScales: i32, )

Set the resize scales.

  • scales An array of resize scales.
  • nbScales Number 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 [setOutputDimensions] See [getScales]

Source

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.

  • size The number of scales to get. If size != nbScales, no scales will be copied.

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

Source

pub fn setResizeMode( self: Pin<&mut IResizeLayer>, interpolationMode: InterpolationMode, )

Set resize mode for an input tensor.

Supported resize modes are Nearest Neighbor and Linear.

See InterpolationMode

Source

pub fn getResizeMode(self: &IResizeLayer) -> InterpolationMode

Get resize mode for an input tensor.

The resize mode.

Source

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.

See ResizeCoordinateTransformation

Source

pub fn getCoordinateTransformation( self: &IResizeLayer, ) -> ResizeCoordinateTransformation

Get coordinate transformation function.

The coordinate transformation function.

Source

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

Source

pub fn getSelectorForSinglePixel(self: &IResizeLayer) -> ResizeSelector

Get the coordinate selector function when resized to single pixel.

The selector function.

Source

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

Source

pub fn getNearestRounding(self: &IResizeLayer) -> ResizeRoundMode

Get rounding mode for nearest neighbor resize.

The rounding mode.

Source

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.

Source

pub fn getCubicCoeff(self: &IResizeLayer) -> f32

Get the coefficient ‘A’ used in cubic interpolation.

See [setCubicCoeff()]

Source

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.

Source

pub fn getExcludeOutside(self: &IResizeLayer) -> bool

Get the state for excluding outside pixels.

See [setExcludeOutside()]

Trait Implementations§

Source§

impl AsLayer for IResizeLayer

Source§

fn as_layer(&self) -> &ILayer

Source§

fn as_layer_pin_mut(&mut self) -> Pin<&mut ILayer>

Source§

impl AsLayerTyped for IResizeLayer

Source§

const TYPE: LayerType = LayerType::kRESIZE

Source§

impl AsRef<ILayer> for IResizeLayer

Source§

fn as_ref(self: &IResizeLayer) -> &ILayer

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl ExternType for IResizeLayer

Source§

type Id = (n, v, i, n, f, e, r, _1, (), I, R, e, s, i, z, e, L, a, y, e, r)

A type-level representation of the type’s C++ namespace and type name. Read more
Source§

type Kind = Opaque

Source§

impl MakeCppStorage for IResizeLayer

Source§

unsafe fn allocate_uninitialized_cpp_storage() -> *mut IResizeLayer

Allocates heap space for this type in C++ and return a pointer to that space, but do not initialize that space (i.e. do not yet call a constructor). Read more
Source§

unsafe fn free_uninitialized_cpp_storage(arg0: *mut IResizeLayer)

Frees a C++ allocation which has not yet had a constructor called. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.