resize¶
- tripy.resize(*args, **kwargs) Tensor [source]¶
This function has multiple overloads:
> resize (input:
tripy.Tensor
, mode:str
, output_shape:Sequence
, align_corners:bool
= False) ->tripy.Tensor
Resizes the input tensor.
- Parameters:
input – 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:
The output tensor after the resize operation.
- Return type:
Example
1input = tp.reshape(tp.arange(16, dtype=tp.float32), (1, 1, 4, 4)) 2output = tp.resize(input, "nearest", output_shape=(1, 1, 8, 8))
>>> input tensor( [[[[0.0000, 1.0000, 2.0000, 3.0000], [4.0000, 5.0000, 6.0000, 7.0000], [8.0000, 9.0000, 10.0000, 11.0000], [12.0000, 13.0000, 14.0000, 15.0000]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4)) >>> output tensor( [[[[0.0000, 0.0000, 1.0000, 1.0000, 2.0000, 2.0000, 3.0000, 3.0000], [0.0000, 0.0000, 1.0000, 1.0000, 2.0000, 2.0000, 3.0000, 3.0000], [4.0000, 4.0000, 5.0000, 5.0000, 6.0000, 6.0000, 7.0000, 7.0000], [4.0000, 4.0000, 5.0000, 5.0000, 6.0000, 6.0000, 7.0000, 7.0000], [8.0000, 8.0000, 9.0000, 9.0000, 10.0000, 10.0000, 11.0000, 11.0000], [8.0000, 8.0000, 9.0000, 9.0000, 10.0000, 10.0000, 11.0000, 11.0000], [12.0000, 12.0000, 13.0000, 13.0000, 14.0000, 14.0000, 15.0000, 15.0000], [12.0000, 12.0000, 13.0000, 13.0000, 14.0000, 14.0000, 15.0000, 15.0000]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 8, 8))
> resize (input:
tripy.Tensor
, mode:str
, scales:Sequence
, align_corners:bool
= False) ->tripy.Tensor
Resizes the input tensor.
- Parameters:
input – 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:
The output tensor after the resize operation.
- Return type:
Example
1input = tp.reshape(tp.arange(16, dtype=tp.float32), (1, 1, 4, 4)) 2output = tp.resize(input, "nearest", scales=(1, 1, 2, 2))
>>> input tensor( [[[[0.0000, 1.0000, 2.0000, 3.0000], [4.0000, 5.0000, 6.0000, 7.0000], [8.0000, 9.0000, 10.0000, 11.0000], [12.0000, 13.0000, 14.0000, 15.0000]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 4, 4)) >>> output tensor( [[[[0.0000, 0.0000, 1.0000, 1.0000, 2.0000, 2.0000, 3.0000, 3.0000], [0.0000, 0.0000, 1.0000, 1.0000, 2.0000, 2.0000, 3.0000, 3.0000], [4.0000, 4.0000, 5.0000, 5.0000, 6.0000, 6.0000, 7.0000, 7.0000], [4.0000, 4.0000, 5.0000, 5.0000, 6.0000, 6.0000, 7.0000, 7.0000], [8.0000, 8.0000, 9.0000, 9.0000, 10.0000, 10.0000, 11.0000, 11.0000], [8.0000, 8.0000, 9.0000, 9.0000, 10.0000, 10.0000, 11.0000, 11.0000], [12.0000, 12.0000, 13.0000, 13.0000, 14.0000, 14.0000, 15.0000, 15.0000], [12.0000, 12.0000, 13.0000, 13.0000, 14.0000, 14.0000, 15.0000, 15.0000]]]], dtype=float32, loc=gpu:0, shape=(1, 1, 8, 8))