mindspore.ops.interpolate
- mindspore.ops.interpolate(x, roi=None, scales=None, sizes=None, coordinate_transformation_mode='align_corners', mode='linear')[source]
Using the interpolate method specified by mode resize the input tensor x.
Warning
This is an experimental prototype that is subject to change.
The roi is reserved interface for ‘crop_and_resize’ coordinate transformation mode, which is not support now.
The Ascend platforms is currently not supported when mode is “linear”.
The ‘half_pixel’ coordinate_transformation_mode is currently not supported on CPU device when mode is “bilinear”.
- Parameters
x (Tensor) – a tensor which to resize. x is a 3-D tensor when mode is “linear”. x is a 4-D tensor when mode is “bilinear”.
roi (tuple[float], optional) – a tuple of float. Only takes effect when attr coordinate_transformation_mode is ‘crop_and_resize’.
scales (tuple[float], optional) – a tuple of float. Describe the scale along each dimension. Its length is the same as that of shape of x. The numbers in scales must all be positive. Only one of scales and sizes can be specified.
sizes (tuple[int], optional) – a tuple of int, describes the shape of the output tensor. The numbers in sizes must all be positive. Only one of scales and sizes can be specified. If sizes is specified, then set scales to ‘None’ in this operator’s input list. It is 1 int elements \((new\_width,)\) when mode is “linear”. It is 2 int elements \((new\_height, new\_width)\) when mode is “bilinear”.
coordinate_transformation_mode (str) –
Default is ‘align_corners’. Describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor. Other optional: ‘half_pixel’, ‘asymmetric’. For example, we want to resize the original tensor along axis x. Let’s denote new_i as the i-th coordinate of the resized tensor along axis x, old_i as the coordinate of the original tensor along axis x, new_length as the length of the resized tensor along axis x, old_length as the length of the original tensor along axis x. We compute the old_i via the following formula:
old_i = new_length != 1 ? new_i * (old_length - 1) / (new_length - 1) : 0 # if set to 'align_corners' old_i = new_length > 1 ? (new_x + 0.5) * old_length / new_length - 0.5 : 0 # if set to 'half_pixel' old_i = new_length != 0 ? new_i * old_length / new_length : 0 # if set to 'asymmetric'
mode (str) – The method used to interpolate: ‘linear’ | ‘bilinear’. Default is ‘linear’.
- Returns
Resized tensor, with the same data type as input x.
- Raises
TypeError – If x is not a Tensor.
TypeError – If the data type of x is not supported.
TypeError – If scales is not a float tuple.
ValueError – If not all numbers in scales are positive.
TypeError – If sizes is not an int tuple.
ValueError – If not all numbers in sizes are positive.
TypeError – If coordinate_transformation_mode is not a string.
ValueError – If coordinate_transformation_mode is not in the support list.
TypeError – If mode is not a string.
ValueError – If mode is not in the support list.
- Supported Platforms:
Ascend
CPU
GPU
Examples
>>> # case 1: linear mode >>> x = Tensor([[[1, 2, 3], [4, 5, 6]]], mindspore.float32) >>> output = ops.interpolate(x, None, None, (6,), "align_corners") >>> print(output) [[[1. 1.4 1.8 2.2 2.6 3.] [4. 4.4 4.8 5.2 5.6 6.]]] >>> # case 2: bilinear mode >>> x = Tensor([[[[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]]], mindspore.float32) >>> output = ops.interpolate(x, None, None, (5, 5), "asymmetric", "bilinear") >>> print(output) [[[[1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.] [1. 2. 3. 4. 5.]]]]