Resize - version 13#
This page documents version 13 of operator Resize. See Resize for the latest version (since version 19).
Domain:
ai.onnxSince version: 13
Resize the input tensor. In general, it calculates every value in the output tensor as a weighted average of neighborhood (a.k.a. sampling locations) in the input tensor. Each dimension value of the output tensor is:
output_dimension = floor(input_dimension * (roi_end - roi_start) * scale) if input \"sizes\" is not specified.
Inputs
X (T1): N-D tensor
roi (T2): 1-D tensor given as [start1, …, startN, end1, …, endN], where N is the rank of X. The RoIs’ coordinates are normalized in the coordinate system of the input image. It only takes effect when coordinate_transformation_mode is “tf_crop_and_resize”
scales (tensor(float)): The scale array along each dimension. It takes value greater than 0. If it’s less than 1, it’s sampling down, otherwise, it’s upsampling. The number of elements of ‘scales’ should be the same as the rank of input ‘X’. One of ‘scales’ and ‘sizes’ MUST be specified and it is an error if both are specified. If ‘sizes’ is needed, the user can use an empty string as the name of ‘scales’ in this operator’s input list.
sizes (tensor(int64)): The size of the output tensor. The number of elements of ‘sizes’ should be the same as the rank of input ‘X’. Only one of ‘scales’ and ‘sizes’ can be specified.
Outputs
Y (T1): N-D tensor after resizing
Attributes
coordinate_transformation_mode (string): Describes how to transform coordinates between the resized and original tensor.
cubic_coeff_a (float): The coefficient ‘a’ used in cubic interpolation. Two common choice are -0.5 (in some cases of TensorFlow) and -0.75 (in PyTorch). Check out Equation (4) in https://ieeexplore.ieee.org/document/1163711 for the details. This attribute is valid only if “mode” is “cubic”.
exclude_outside (int): If set to 1, the weight of sampling locations outside the tensor will be set to 0 and the weight will be renormalized so that their sum is 1.0. The default value is 0.
extrapolation_value (float): When coordinate_transformation_mode is “tf_crop_and_resize” and x_original is outside the range [0, length_original - 1], this value is used as the corresponding output value. Default is 0.0f.
mode (string): Three interpolation modes: nearest (default), linear and cubic. The “linear” mode includes linear interpolation for 1D tensor and N-linear interpolation for N-D tensor (for example, bilinear interpolation for 2D tensor). The “cubic” mode includes cubic interpolation for 1D tensor and N-cubic interpolation for N-D tensor (for example, bicubic interpolation for 2D tensor).
nearest_mode (string): Four modes: round_prefer_floor (default, as known as round half down), round_prefer_ceil (as known as round half up), floor, ceil. Only used by nearest interpolation. It indicates how to get “nearest” pixel in input tensor from x_original, so this attribute is valid only if “mode” is “nearest”.
Type Constraints
T1: Constrain input ‘X’ and output ‘Y’ to all tensor types. Allowed types: tensor(bfloat16), tensor(bool), tensor(complex128), tensor(complex64), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(string), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).
T2: Constrain roi type to float or double. Allowed types: tensor(double), tensor(float), tensor(float16).
Examples#
test_cc_resize_upsample_scales_nearest_1d
Node:
Resize(X, "", scales) -> (Y)
Attributes:
mode = "nearest"
coordinate_transformation_mode = "asymmetric"
Inputs:
X: shape=(3,), dtype=float32
[10., 20., 30.]
scales: shape=(1,), dtype=float32
[2.]
Outputs:
Y: shape=(6,), dtype=float32
[10., 10., 20., 20., 30., 30.]
test_cc_resize_upsample_scales_nearest_asymmetric
Node:
Resize(X, "", scales) -> (Y)
Attributes:
mode = "nearest"
coordinate_transformation_mode = "asymmetric"
Inputs:
X: shape=(1, 1, 2, 2), dtype=float32
[[[[1., 2.],
[3., 4.]]]]
scales: shape=(4,), dtype=float32
[1., 1., 2., 3.]
Outputs:
Y: shape=(1, 1, 4, 6), dtype=float32
[[[[1., 1., 2., 2., 2., 2.],
[1., 1., 2., 2., 2., 2.],
[3., 3., 4., 4., 4., 4.],
[3., 3., 4., 4., 4., 4.]]]]
test_cc_resize_upsample_sizes_nearest_asymmetric
Node:
Resize(X, "", "", sizes) -> (Y)
Attributes:
mode = "nearest"
coordinate_transformation_mode = "asymmetric"
Inputs:
X: shape=(1, 1, 2, 2), dtype=float32
[[[[1., 2.],
[3., 4.]]]]
sizes: shape=(4,), dtype=int64
[1, 1, 4, 6]
Outputs:
Y: shape=(1, 1, 4, 6), dtype=float32
[[[[1., 1., 2., 2., 2., 2.],
[1., 1., 2., 2., 2., 2.],
[3., 3., 4., 4., 4., 4.],
[3., 3., 4., 4., 4., 4.]]]]
test_cc_shape_inference_resize_tile
Node:
Resize(X, "", scales) -> (resized_out)
Attributes:
mode = "nearest"
coordinate_transformation_mode = "asymmetric"
Inputs:
X: shape=(10, 6), dtype=float32
[[ 1., 2., 3., 4., 5., 6.],
[ 7., 8., 9., 10., 11., 12.],
[13., 14., 15., 16., 17., 18.],
[19., 20., 21., 22., 23., 24.],
[25., 26., 27., 28., 29., 30.],
[31., 32., 33., 34., 35., 36.],
[37., 38., 39., 40., 41., 42.],
[43., 44., 45., 46., 47., 48.],
[49., 50., 51., 52., 53., 54.],
[55., 56., 57., 58., 59., 60.]]
Outputs:
resized_out: shape=(10, 6), dtype=float32
[[ 1., 3., 5., 1., 3., 5.],
[13., 15., 17., 13., 15., 17.],
[25., 27., 29., 25., 27., 29.],
[37., 39., 41., 37., 39., 41.],
[49., 51., 53., 49., 51., 53.],
[ 1., 3., 5., 1., 3., 5.],
[13., 15., 17., 13., 15., 17.],
[25., 27., 29., 25., 27., 29.],
[37., 39., 41., 37., 39., 41.],
[49., 51., 53., 49., 51., 53.]]
test_resize_downsample_scales_nearest
Node:
Resize(X, "", scales) -> (Y)
Attributes:
mode = "nearest"
Inputs:
X: shape=(1, 1, 2, 4), dtype=float32
[[[[1., 2., 3., 4.],
[5., 6., 7., 8.]]]]
scales: shape=(4,), dtype=float32
[1. , 1. , 0.6, 0.6]
Outputs:
Y: shape=(1, 1, 1, 2), dtype=float32
[[[[1., 3.]]]]
test_resize_downsample_sizes_nearest
Node:
Resize(X, "", "", sizes) -> (Y)
Attributes:
mode = "nearest"
Inputs:
X: shape=(1, 1, 2, 4), dtype=float32
[[[[1., 2., 3., 4.],
[5., 6., 7., 8.]]]]
sizes: shape=(4,), dtype=int64
[1, 1, 1, 3]
Outputs:
Y: shape=(1, 1, 1, 3), dtype=float32
[[[[1., 2., 4.]]]]
test_resize_upsample_scales_nearest
Node:
Resize(X, "", scales) -> (Y)
Attributes:
mode = "nearest"
Inputs:
X: shape=(1, 1, 2, 2), dtype=float32
[[[[1., 2.],
[3., 4.]]]]
scales: shape=(4,), dtype=float32
[1., 1., 2., 3.]
Outputs:
Y: shape=(1, 1, 4, 6), dtype=float32
[[[[1., 1., 1., 2., 2., 2.],
[1., 1., 1., 2., 2., 2.],
[3., 3., 3., 4., 4., 4.],
[3., 3., 3., 4., 4., 4.]]]]
test_resize_upsample_sizes_nearest
Node:
Resize(X, "", "", sizes) -> (Y)
Attributes:
mode = "nearest"
Inputs:
X: shape=(1, 1, 2, 2), dtype=float32
[[[[1., 2.],
[3., 4.]]]]
sizes: shape=(4,), dtype=int64
[1, 1, 7, 8]
Outputs:
Y: shape=(1, 1, 7, 8), dtype=float32
[[[[1., 1., 1., 1., 2., 2., 2., 2.],
[1., 1., 1., 1., 2., 2., 2., 2.],
[1., 1., 1., 1., 2., 2., 2., 2.],
[1., 1., 1., 1., 2., 2., 2., 2.],
[3., 3., 3., 3., 4., 4., 4., 4.],
[3., 3., 3., 3., 4., 4., 4., 4.],
[3., 3., 3., 3., 4., 4., 4., 4.]]]]
test_resize_upsample_sizes_nearest_ceil_half_pixel
Node:
Resize(X, "", "", sizes) -> (Y)
Attributes:
mode = "nearest"
coordinate_transformation_mode = "half_pixel"
nearest_mode = "ceil"
Inputs:
X: shape=(1, 1, 4, 4), dtype=float32
[[[[ 1., 2., 3., 4.],
[ 5., 6., 7., 8.],
[ 9., 10., 11., 12.],
[13., 14., 15., 16.]]]]
sizes: shape=(4,), dtype=int64
[1, 1, 8, 8]
Outputs:
Y: shape=(1, 1, 8, 8), dtype=float32
[[[[ 1., 2., 2., 3., 3., 4., 4., 4.],
[ 5., 6., 6., 7., 7., 8., 8., 8.],
[ 5., 6., 6., 7., 7., 8., 8., 8.],
[ 9., 10., 10., 11., 11., 12., 12., 12.],
[ 9., 10., 10., 11., 11., 12., 12., 12.],
[13., 14., 14., 15., 15., 16., 16., 16.],
[13., 14., 14., 15., 15., 16., 16., 16.],
[13., 14., 14., 15., 15., 16., 16., 16.]]]]
test_resize_upsample_sizes_nearest_floor_align_corners
Node:
Resize(X, "", "", sizes) -> (Y)
Attributes:
mode = "nearest"
coordinate_transformation_mode = "align_corners"
nearest_mode = "floor"
Inputs:
X: shape=(1, 1, 4, 4), dtype=float32
[[[[ 1., 2., 3., 4.],
[ 5., 6., 7., 8.],
[ 9., 10., 11., 12.],
[13., 14., 15., 16.]]]]
sizes: shape=(4,), dtype=int64
[1, 1, 8, 8]
Outputs:
Y: shape=(1, 1, 8, 8), dtype=float32
[[[[ 1., 1., 1., 2., 2., 3., 3., 4.],
[ 1., 1., 1., 2., 2., 3., 3., 4.],
[ 1., 1., 1., 2., 2., 3., 3., 4.],
[ 5., 5., 5., 6., 6., 7., 7., 8.],
[ 5., 5., 5., 6., 6., 7., 7., 8.],
[ 9., 9., 9., 10., 10., 11., 11., 12.],
[ 9., 9., 9., 10., 10., 11., 11., 12.],
[13., 13., 13., 14., 14., 15., 15., 16.]]]]
test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric
Node:
Resize(X, "", "", sizes) -> (Y)
Attributes:
mode = "nearest"
coordinate_transformation_mode = "asymmetric"
nearest_mode = "round_prefer_ceil"
Inputs:
X: shape=(1, 1, 4, 4), dtype=float32
[[[[ 1., 2., 3., 4.],
[ 5., 6., 7., 8.],
[ 9., 10., 11., 12.],
[13., 14., 15., 16.]]]]
sizes: shape=(4,), dtype=int64
[1, 1, 8, 8]
Outputs:
Y: shape=(1, 1, 8, 8), dtype=float32
[[[[ 1., 2., 2., 3., 3., 4., 4., 4.],
[ 5., 6., 6., 7., 7., 8., 8., 8.],
[ 5., 6., 6., 7., 7., 8., 8., 8.],
[ 9., 10., 10., 11., 11., 12., 12., 12.],
[ 9., 10., 10., 11., 11., 12., 12., 12.],
[13., 14., 14., 15., 15., 16., 16., 16.],
[13., 14., 14., 15., 15., 16., 16., 16.],
[13., 14., 14., 15., 15., 16., 16., 16.]]]]
Differences with previous version (11)#
SchemaDiff: Resize (domain 'ai.onnx')
old version: 11
new version: 13
breaking: no
Type constraints:
changed ‘T1’: added types: [‘tensor(bfloat16)’]