Resize - version 13#

This page documents version 13 of operator Resize. See Resize for the latest version (since version 19).

  • Domain: ai.onnx

  • Since 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

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: yes

Breaking reasons:

  • attribute ‘mode’ (removed): type=STRING; required=False

  • attribute ‘cubic_coeff_a’ (removed): type=FLOAT; required=False

  • attribute ‘exclude_outside’ (removed): type=INT; required=False

  • attribute ‘coordinate_transformation_mode’ (removed): type=STRING; required=False

  • attribute ‘nearest_mode’ (removed): type=STRING; required=False

  • attribute ‘extrapolation_value’ (removed): type=FLOAT; required=False

Attributes:

  • [BREAKING] removed ‘mode’: type=STRING; required=False

  • [BREAKING] removed ‘cubic_coeff_a’: type=FLOAT; required=False

  • [BREAKING] removed ‘exclude_outside’: type=INT; required=False

  • [BREAKING] removed ‘coordinate_transformation_mode’: type=STRING; required=False

  • [BREAKING] removed ‘nearest_mode’: type=STRING; required=False

  • [BREAKING] removed ‘extrapolation_value’: type=FLOAT; required=False

Type constraints:

  • changed ‘T1’: added types: [‘tensor(bfloat16)’]