Resize¶
Resize an input tensor into an output tensor. The output shape is either set directly using shape or calculated by the scales parameters.
Attributes¶
resize_mode Controls what kind of resize is used, defaults to NEAREST.
NEARESTNearest neighbor resizing on the innermost m dimensions of an input of rank N where \(0\leq m \leqmin(3,N)\).LINEARLinear resizing on the innermost m dimensions of an input of rank N where \(0 \leq m \leqmin(3,N)\).CUBICCubic resizing innermost 2 dimensions of N-D, N >= 2.
shape The output shape. The number of elements must be the number of dimensions in input.
scales List of resize scales. Must have the same number of dimensions as the input.
coordinate_transformation Controls how to map the resized coordinate back to the original coordinate, defaults to ASYMMETRIC.
ALIGN_CORNERSIn this mode: \(x_{original}=x_{resized} \cdot \frac{length_{original}-1}{length_{resized}-1}\).ASYMMETRICIn this mode: \(x_{original} = x_{resized} \cdot \frac{length_{original}}{length_{resized}}\).HALF_PIXELIn this mode: \(x_{original} = (x_{resized} + 0.5) \cdot \frac{length_{original}}{length_{resized}} -0.5\).
selector_for_single_pixel The coordinate selector when resize to single pixel output, defaults to FORMULA.
FORMULAUse formula to map the original index.UPPERSelect the upper left pixel.
nearest_rounding The rounding mode for nearest neighbor resize, defaults to FLOOR.
HALF_UPRound half up.HALF_DOWNRound half down.FLOORRound to floor.CEILRound to ceil.
cubic_coeff The cubic coefficient to use when cubic resize is used.
Outputs¶
output: tensor of type T1.
Data Types¶
T1: int8, float16, float32
Shape Information¶
input0 is a tensor with a shape of \([a_0,...,a_n]\).
input1 has shape \([n]\).
output is a tensor with a shape of \([b_0,...,b_n]\), where:
When
shapeis set, \(b_i = shape_i\).When
scalesis set, \(b_i = \lfloor a_i \cdot scales_i \rfloor\).
Volume Limits¶
input and output can have up to \(2^{31}\) elements.
DLA Support¶
DLA FP16 and DLA INT8 are supported.
Supported combination of parameters are:
when resize_mode is NEAREST:
coordinate_transformation |
selector_for_single_pixel |
nearest_rounding |
ASYMMETRIC |
FORMULA |
FLOOR |
HALF_PIXEL |
FORMULA |
HALF_DOWN |
HALF_PIXEL |
FORMULA |
HALF_UP |
when resize_mode is LINEAR:
coordinate_transformation |
selector_for_single_pixel |
HALF_PIXEL |
FORMULA |
HALF_PIXEL |
UPPER |
Examples¶
Linear Resize
input = network.add_input("input", dtype=trt.float32, shape=(1, 1, 3, 3))
layer = network.add_resize(input)
layer.resize_mode = trt.InterpolationMode.LINEAR
layer.shape = (1, 1, 5, 5)
layer.coordinate_transformation = trt.ResizeCoordinateTransformation.ALIGN_CORNERS
network.mark_output(layer.get_output(0))
inputs[input.name] = np.array([[[[0, 1, 2], [3, 4, 5], [6, 7, 8]]]])
outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = np.array(
[
[
[0, 0.5, 1, 1.5, 2],
[1.5, 2, 2.5, 3, 3.5],
[3, 3.5, 4, 4.5, 5],
[4.5, 5, 5.5, 6, 6.5],
[6, 6.5, 7, 7.5, 8],
]
]
)
Nearest Resize, Shape Is Calculated By Using Scales
input = network.add_input("input", dtype=trt.float32, shape=(1, 1, 3, 3))
layer = network.add_resize(input)
layer.resize_mode = trt.InterpolationMode.NEAREST
layer.scales = (1, 1, 2, 2)
layer.coordinate_transformation = trt.ResizeCoordinateTransformation.ALIGN_CORNERS
network.mark_output(layer.get_output(0))
inputs[input.name] = np.array([[[[0, 1, 2], [3, 4, 5], [6, 7, 8]]]])
outputs[layer.get_output(0).name] = layer.get_output(0).shape
expected[layer.get_output(0).name] = np.array(
[
[
[
[0.0, 0.0, 0.0, 1.0, 1.0, 2.0],
[0.0, 0.0, 0.0, 1.0, 1.0, 2.0],
[0.0, 0.0, 0.0, 1.0, 1.0, 2.0],
[3.0, 3.0, 3.0, 4.0, 4.0, 5.0],
[3.0, 3.0, 3.0, 4.0, 4.0, 5.0],
[6.0, 6.0, 6.0, 7.0, 7.0, 8.0],
]
]
]
)
C++ API¶
For more information about the C++ IResizeLayer operator, refer to the C++ IResizeLayer documentation
Python API¶
For more information about the Python IResizeLayer operator, refer to the Python IResizeLayer documentation