resize¶
- nvtripy.resize(*args, **kwargs) Tensor [source]¶
This function has multiple overloads:
nvtripy.resize(input:
nvtripy.Tensor
, output_shape: Sequence[int |nvtripy.DimensionSize
], mode: str = linear, align_corners: bool = False) ->nvtripy.Tensor
Resizes the input tensor.
- Parameters:
input – [dtype=T1] The input tensor.
mode – The resize operation’s algorithm. Must be one of: [“cubic”, linear”, “nearest”].
output_shape – The output shape of the resize operation.
align_corners – If set to
True
, the input and output tensors are aligned by the center points of their corner pixels, preserving the values at the corner pixels. If set toFalse
, the input and output tensors are aligned by the corner points of their corner pixels. Only in effect whenmode
is"cubic"
or"linear"
.
- Returns:
[dtype=T1] The output tensor after the resize operation.
- Return type:
Example: Nearest Neighbor Interpolation
1input = tp.reshape(tp.arange(4), (1, 1, 2, 2)) 2output = tp.resize(input, output_shape=(1, 1, 4, 4), mode="nearest")
Local Variables¶>>> input tensor( [[[[0, 1], [2, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 2, 2)) >>> output tensor( [[[[0, 0, 1, 1], [0, 0, 1, 1], [2, 2, 3, 3], [2, 2, 3, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4))
Example: Linear Interpolation
1input = tp.reshape(tp.arange(4), (1, 1, 2, 2)) 2output = tp.resize(input, output_shape=(1, 1, 4, 4), mode="linear")
Local Variables¶>>> input tensor( [[[[0, 1], [2, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 2, 2)) >>> output tensor( [[[[0, 0.25, 0.75, 1], [0.5, 0.75, 1.25, 1.5], [1.5, 1.75, 2.25, 2.5], [2, 2.25, 2.75, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4))
Example: Cubic Interpolation
1input = tp.reshape(tp.arange(4), (1, 1, 2, 2)) 2output = tp.resize(input, output_shape=(1, 1, 4, 4), mode="cubic")
Local Variables¶>>> input tensor( [[[[0, 1], [2, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 2, 2)) >>> output tensor( [[[[-0.316406, 0.015625, 0.5625, 0.894531], [0.347656, 0.679688, 1.22656, 1.55859], [1.44141, 1.77344, 2.32031, 2.65234], [2.10547, 2.4375, 2.98438, 3.31641]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4))
nvtripy.resize(input:
nvtripy.Tensor
, scales: Sequence[numbers.Number], mode: str = linear, align_corners: bool = False) ->nvtripy.Tensor
Resizes the input tensor.
- Parameters:
input – [dtype=T1] The input tensor.
mode – The resize operation’s algorithm. Must be one of: [“cubic”, linear”, “nearest”].
scales – A sequence of scale factors for each dimension. Must have the same length as input tensor’s rank.
align_corners – If set to
True
, the input and output tensors are aligned by the center points of their corner pixels, preserving the values at the corner pixels. If set toFalse
, the input and output tensors are aligned by the corner points of their corner pixels. Only in effect whenmode
is"cubic"
or"linear"
.
- Returns:
[dtype=T1] The output tensor after the resize operation.
- Return type:
Example: Nearest Neighbor Interpolation
1input = tp.reshape(tp.arange(4), (1, 1, 2, 2)) 2output = tp.resize(input, scales=(1, 1, 2, 2), mode="nearest")
Local Variables¶>>> input tensor( [[[[0, 1], [2, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 2, 2)) >>> output tensor( [[[[0, 0, 1, 1], [0, 0, 1, 1], [2, 2, 3, 3], [2, 2, 3, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4))
Example: Linear Interpolation
1input = tp.reshape(tp.arange(4), (1, 1, 2, 2)) 2output = tp.resize(input, scales=(1, 1, 2, 2), mode="linear")
Local Variables¶>>> input tensor( [[[[0, 1], [2, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 2, 2)) >>> output tensor( [[[[0, 0.25, 0.75, 1], [0.5, 0.75, 1.25, 1.5], [1.5, 1.75, 2.25, 2.5], [2, 2.25, 2.75, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4))
Example: Cubic Interpolation
1input = tp.reshape(tp.arange(4), (1, 1, 2, 2)) 2output = tp.resize(input, scales=(1, 1, 2, 2), mode="cubic")
Local Variables¶>>> input tensor( [[[[0, 1], [2, 3]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 2, 2)) >>> output tensor( [[[[-0.316406, 0.015625, 0.5625, 0.894531], [0.347656, 0.679688, 1.22656, 1.55859], [1.44141, 1.77344, 2.32031, 2.65234], [2.10547, 2.4375, 2.98438, 3.31641]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4))