From 097b0307b66b81f6c67b31abc775203e4a06a80b Mon Sep 17 00:00:00 2001 From: Josh Fromm Date: Fri, 1 Oct 2021 12:46:37 -0700 Subject: [PATCH 1/4] Fix handling of optional inputs. --- python/tvm/relay/frontend/onnx.py | 12 +- tests/python/frontend/onnx/test_forward.py | 310 +++++++++++---------- 2 files changed, 164 insertions(+), 158 deletions(-) diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 3479e1e7c36e..beaa684ba23f 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -2716,15 +2716,17 @@ def _impl_v11(cls, inputs, attr, params): exclude = attr.get("exclude_outside", 0) scale = inputs[2] - scale_shape = infer_shape(scale) - if len(inputs) == 4: + size = inputs[3] + if size is not None: assert ( - len(scale_shape) == 0 or scale_shape[0] == 0 + scale is None ), "One of scale or size should be passed, not both." - size = inputs[3] else: + scale_type = infer_type(scale) + scale_shape = scale_type.checked_type.shape + scale_dtype = scale_type.checked_type.dtype assert len(scale_shape) != 0, "One of scale or size should be passed." - size = _op.cast(shape_of(inputs[0]), infer_type(scale).checked_type.dtype) * scale + size = _op.cast(shape_of(inputs[0]), scale_dtype) * scale out_size = fold_constant(_op.strided_slice(size, [2], [4])) out = None if ndims == 3: diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 2301747034dd..76ea4fe07670 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -3962,150 +3962,154 @@ def test_gru(target, dev): ) -@tvm.testing.parametrize_targets -def test_resize(target, dev): - def verify(ishape, oshape, scales, mode, coord_trans="asymmetric", alpha=0.5, exclude=False): - nodes = [ - make_constant_node("roi", onnx.TensorProto.FLOAT, (0,), []), - make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales), - ] - input_names = ["X", "roi", "scales"] - if oshape != []: - nodes.append( - make_constant_node("sizes", onnx.TensorProto.INT64, (len(oshape),), oshape) - ) - input_names.append("sizes") - nodes.append( - helper.make_node( - "Resize", - inputs=input_names, - outputs=["Y"], - mode=mode, - coordinate_transformation_mode=coord_trans, - cubic_coeff_a=alpha, - exclude_outside=exclude, - ) - ) - - if oshape == []: - oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] - graph = helper.make_graph( - nodes, - "resize_test", - inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], - outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], - ) - - model = helper.make_model(graph, producer_name="resize_test") - - verify_with_ort( - model, - [ishape], - [oshape], - use_vm=True, - opset=11, - freeze_params=True, - target=target, - dev=dev, - ) - - for ndim in [1, 2, 3]: - method = "nearest" - for coord_trans in ["asymmetric", "align_corners", "half_pixel"]: - # upsampling - verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method, coord_trans) - # downsampling - verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method, coord_trans) - # scales are specified instead of sizes - verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method, coord_trans) - verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method, coord_trans) - - method = "linear" - # upsampling - verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method) - # downsampling - verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method) - # scales are specified instead of sizes - verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method) - verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method) - - if ndim == 2: - # ONNX Runtime only supports cubic interpolation for 2D images - method = "cubic" - for alpha in [0.5, 0.75]: - for exclude in [True, False]: - # upsampling - verify( - [1, 16] + [32] * ndim, - [1, 16] + [64] * ndim, - [], - method, - alpha=alpha, - exclude=exclude, - ) - # downsampling - verify( - [1, 16] + [32] * ndim, - [1, 16] + [16] * ndim, - [], - method, - alpha=alpha, - exclude=exclude, - ) - # scales are specified instead of sizes - verify( - [1, 16] + [32] * ndim, - [], - [1, 1] + [0.5] * ndim, - method, - alpha=alpha, - exclude=exclude, - ) - verify( - [1, 16] + [32] * ndim, - [], - [1, 1] + [2] * ndim, - method, - alpha=alpha, - exclude=exclude, - ) - - def verify_opset_10(ishape, scales, mode): - nodes = [ - make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales), - ] - input_names = ["X", "scales"] - nodes.append( - helper.make_node( - "Resize", - inputs=input_names, - outputs=["Y"], - mode=mode, - ) - ) - - oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] - graph = helper.make_graph( - nodes, - "resize_test", - inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], - outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], - ) - - model = helper.make_model(graph, producer_name="resize_test") - verify_with_ort( - model, - [ishape], - [oshape], - use_vm=True, - freeze_params=True, - opset=10, - target=target, - dev=dev, - ) - - verify_opset_10([1, 16, 32, 32], [1, 1, 2, 2], "nearest") - verify_opset_10([1, 16, 32, 32], [1, 1, 0.5, 0.5], "linear") +#@tvm.testing.parametrize_targets +#def test_resize(target, dev): +# def verify(ishape, oshape, scales, mode, coord_trans="asymmetric", alpha=0.5, exclude=False): +# nodes = [ +# make_constant_node("roi", onnx.TensorProto.FLOAT, (0,), []), +# ] +# input_names = ["X", "roi"] +# if scales == []: +# input_names.append("") +# else: +# input_names.append("scales") +# nodes.append(make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales)) +# if oshape != []: +# nodes.append( +# make_constant_node("sizes", onnx.TensorProto.INT64, (len(oshape),), oshape) +# ) +# input_names.append("sizes") +# nodes.append( +# helper.make_node( +# "Resize", +# inputs=input_names, +# outputs=["Y"], +# mode=mode, +# coordinate_transformation_mode=coord_trans, +# cubic_coeff_a=alpha, +# exclude_outside=exclude, +# ) +# ) +# +# if oshape == []: +# oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] +# graph = helper.make_graph( +# nodes, +# "resize_test", +# inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], +# outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], +# ) +# +# model = helper.make_model(graph, producer_name="resize_test") +# +# verify_with_ort( +# model, +# [ishape], +# [oshape], +# use_vm=True, +# opset=13, +# freeze_params=True, +# target=target, +# dev=dev, +# ) +# +# for ndim in [1, 2, 3]: +# method = "nearest" +# for coord_trans in ["asymmetric", "align_corners", "half_pixel"]: +# # upsampling +# verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method, coord_trans) +# # downsampling +# verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method, coord_trans) +# # scales are specified instead of sizes +# verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method, coord_trans) +# verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method, coord_trans) +# +# method = "linear" +# # upsampling +# verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method) +# # downsampling +# verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method) +# # scales are specified instead of sizes +# verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method) +# verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method) +# +# if ndim == 2: +# # ONNX Runtime only supports cubic interpolation for 2D images +# method = "cubic" +# for alpha in [0.5, 0.75]: +# for exclude in [True, False]: +# # upsampling +# verify( +# [1, 16] + [32] * ndim, +# [1, 16] + [64] * ndim, +# [], +# method, +# alpha=alpha, +# exclude=exclude, +# ) +# # downsampling +# verify( +# [1, 16] + [32] * ndim, +# [1, 16] + [16] * ndim, +# [], +# method, +# alpha=alpha, +# exclude=exclude, +# ) +# # scales are specified instead of sizes +# verify( +# [1, 16] + [32] * ndim, +# [], +# [1, 1] + [0.5] * ndim, +# method, +# alpha=alpha, +# exclude=exclude, +# ) +# verify( +# [1, 16] + [32] * ndim, +# [], +# [1, 1] + [2] * ndim, +# method, +# alpha=alpha, +# exclude=exclude, +# ) +# +# def verify_opset_10(ishape, scales, mode): +# nodes = [ +# make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales), +# ] +# input_names = ["X", "scales"] +# nodes.append( +# helper.make_node( +# "Resize", +# inputs=input_names, +# outputs=["Y"], +# mode=mode, +# ) +# ) +# +# oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] +# graph = helper.make_graph( +# nodes, +# "resize_test", +# inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], +# outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], +# ) +# +# model = helper.make_model(graph, producer_name="resize_test") +# verify_with_ort( +# model, +# [ishape], +# [oshape], +# use_vm=True, +# freeze_params=True, +# opset=10, +# target=target, +# dev=dev, +# ) +# +# verify_opset_10([1, 16, 32, 32], [1, 1, 2, 2], "nearest") +# verify_opset_10([1, 16, 32, 32], [1, 1, 0.5, 0.5], "linear") @tvm.testing.parametrize_targets @@ -4954,15 +4958,15 @@ def verify_eyelike(indata): "test_reduce_sum_keepdims_random", "test_reduce_sum_negative_axes_keepdims_example", "test_reduce_sum_negative_axes_keepdims_random", - "test_resize_downsample_sizes_cubic", - "test_resize_downsample_sizes_linear_pytorch_half_pixel", - "test_resize_downsample_sizes_nearest", - "test_resize_tf_crop_and_resize", - "test_resize_upsample_sizes_cubic", - "test_resize_upsample_sizes_nearest", - "test_resize_upsample_sizes_nearest_ceil_half_pixel", - "test_resize_upsample_sizes_nearest_floor_align_corners", - "test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric", + #"test_resize_downsample_sizes_cubic", + #"test_resize_downsample_sizes_linear_pytorch_half_pixel", + #"test_resize_downsample_sizes_nearest", + #"test_resize_tf_crop_and_resize", + #"test_resize_upsample_sizes_cubic", + #"test_resize_upsample_sizes_nearest", + #"test_resize_upsample_sizes_nearest_ceil_half_pixel", + #"test_resize_upsample_sizes_nearest_floor_align_corners", + #"test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric", "test_rnn_seq_length", "test_round", "test_scan9_sum", From 521582ea6b9629fab5395dada965e5684771d551 Mon Sep 17 00:00:00 2001 From: Josh Fromm Date: Fri, 1 Oct 2021 12:50:38 -0700 Subject: [PATCH 2/4] Missed one test in the ignore list. --- tests/python/frontend/onnx/test_forward.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 76ea4fe07670..227be50f065f 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -4961,7 +4961,8 @@ def verify_eyelike(indata): #"test_resize_downsample_sizes_cubic", #"test_resize_downsample_sizes_linear_pytorch_half_pixel", #"test_resize_downsample_sizes_nearest", - #"test_resize_tf_crop_and_resize", + "test_resize_tf_crop_and_resize", + "test_resize_downsample_sizes_nearest_tf_half_pixel_for_nn", #"test_resize_upsample_sizes_cubic", #"test_resize_upsample_sizes_nearest", #"test_resize_upsample_sizes_nearest_ceil_half_pixel", From 7b76aa2f83caff77474f0d77d5c4fd29637f57eb Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 4 Oct 2021 09:57:42 -0600 Subject: [PATCH 3/4] split 11 and 13 --- python/tvm/relay/frontend/onnx.py | 46 ++- tests/python/frontend/onnx/test_forward.py | 307 ++++++++++----------- 2 files changed, 184 insertions(+), 169 deletions(-) diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index beaa684ba23f..5ec038711110 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -2697,6 +2697,40 @@ def _impl_v10(cls, inputs, attr, params): @classmethod def _impl_v11(cls, inputs, attr, params): + scale = inputs[2] + scale_shape = infer_shape(scale) + if len(inputs) == 4: + assert ( + len(scale_shape) == 0 or scale_shape[0] == 0 + ), "One of scale or size should be passed, not both." + size = inputs[3] + else: + assert len(scale_shape) != 0, "One of scale or size should be passed." + size = _op.cast(shape_of(inputs[0]), infer_type(scale).checked_type.dtype) * scale + return cls.v11_13_common(inputs, size, attr, params) + + @classmethod + def _impl_v13(cls, inputs, attr, params): + scale = inputs[2] + size = inputs[3] + if size is not None: + assert scale is None, "One of scale or size should be passed, not both." + else: + scale_type = infer_type(scale) + scale_shape = scale_type.checked_type.shape + scale_dtype = scale_type.checked_type.dtype + assert len(scale_shape) != 0, "One of scale or size should be passed." + size = _op.cast(shape_of(inputs[0]), scale_dtype) * scale + + return cls.v11_13_common(inputs, size, attr, params) + + @classmethod + def v11_13_common(cls, inputs, size, attr, params): + """ + Resize v11 and Resize v13 are identical except in how + they handle passing in scale and size. This utility + provides the implementation for both + """ ndims = len(infer_shape(inputs[0])) mode = attr.get("mode").decode("ascii") if mode == "nearest": @@ -2715,18 +2749,6 @@ def _impl_v11(cls, inputs, attr, params): alpha = attr.get("cubic_coeff_a", -0.75) exclude = attr.get("exclude_outside", 0) - scale = inputs[2] - size = inputs[3] - if size is not None: - assert ( - scale is None - ), "One of scale or size should be passed, not both." - else: - scale_type = infer_type(scale) - scale_shape = scale_type.checked_type.shape - scale_dtype = scale_type.checked_type.dtype - assert len(scale_shape) != 0, "One of scale or size should be passed." - size = _op.cast(shape_of(inputs[0]), scale_dtype) * scale out_size = fold_constant(_op.strided_slice(size, [2], [4])) out = None if ndims == 3: diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 227be50f065f..0a778ff2d67d 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -3962,154 +3962,156 @@ def test_gru(target, dev): ) -#@tvm.testing.parametrize_targets -#def test_resize(target, dev): -# def verify(ishape, oshape, scales, mode, coord_trans="asymmetric", alpha=0.5, exclude=False): -# nodes = [ -# make_constant_node("roi", onnx.TensorProto.FLOAT, (0,), []), -# ] -# input_names = ["X", "roi"] -# if scales == []: -# input_names.append("") -# else: -# input_names.append("scales") -# nodes.append(make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales)) -# if oshape != []: -# nodes.append( -# make_constant_node("sizes", onnx.TensorProto.INT64, (len(oshape),), oshape) -# ) -# input_names.append("sizes") -# nodes.append( -# helper.make_node( -# "Resize", -# inputs=input_names, -# outputs=["Y"], -# mode=mode, -# coordinate_transformation_mode=coord_trans, -# cubic_coeff_a=alpha, -# exclude_outside=exclude, -# ) -# ) -# -# if oshape == []: -# oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] -# graph = helper.make_graph( -# nodes, -# "resize_test", -# inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], -# outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], -# ) -# -# model = helper.make_model(graph, producer_name="resize_test") -# -# verify_with_ort( -# model, -# [ishape], -# [oshape], -# use_vm=True, -# opset=13, -# freeze_params=True, -# target=target, -# dev=dev, -# ) -# -# for ndim in [1, 2, 3]: -# method = "nearest" -# for coord_trans in ["asymmetric", "align_corners", "half_pixel"]: -# # upsampling -# verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method, coord_trans) -# # downsampling -# verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method, coord_trans) -# # scales are specified instead of sizes -# verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method, coord_trans) -# verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method, coord_trans) -# -# method = "linear" -# # upsampling -# verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method) -# # downsampling -# verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method) -# # scales are specified instead of sizes -# verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method) -# verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method) -# -# if ndim == 2: -# # ONNX Runtime only supports cubic interpolation for 2D images -# method = "cubic" -# for alpha in [0.5, 0.75]: -# for exclude in [True, False]: -# # upsampling -# verify( -# [1, 16] + [32] * ndim, -# [1, 16] + [64] * ndim, -# [], -# method, -# alpha=alpha, -# exclude=exclude, -# ) -# # downsampling -# verify( -# [1, 16] + [32] * ndim, -# [1, 16] + [16] * ndim, -# [], -# method, -# alpha=alpha, -# exclude=exclude, -# ) -# # scales are specified instead of sizes -# verify( -# [1, 16] + [32] * ndim, -# [], -# [1, 1] + [0.5] * ndim, -# method, -# alpha=alpha, -# exclude=exclude, -# ) -# verify( -# [1, 16] + [32] * ndim, -# [], -# [1, 1] + [2] * ndim, -# method, -# alpha=alpha, -# exclude=exclude, -# ) -# -# def verify_opset_10(ishape, scales, mode): -# nodes = [ -# make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales), -# ] -# input_names = ["X", "scales"] -# nodes.append( -# helper.make_node( -# "Resize", -# inputs=input_names, -# outputs=["Y"], -# mode=mode, -# ) -# ) -# -# oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] -# graph = helper.make_graph( -# nodes, -# "resize_test", -# inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], -# outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], -# ) -# -# model = helper.make_model(graph, producer_name="resize_test") -# verify_with_ort( -# model, -# [ishape], -# [oshape], -# use_vm=True, -# freeze_params=True, -# opset=10, -# target=target, -# dev=dev, -# ) -# -# verify_opset_10([1, 16, 32, 32], [1, 1, 2, 2], "nearest") -# verify_opset_10([1, 16, 32, 32], [1, 1, 0.5, 0.5], "linear") +@tvm.testing.parametrize_targets +def test_resize(target, dev): + def verify(ishape, oshape, scales, mode, coord_trans="asymmetric", alpha=0.5, exclude=False): + nodes = [ + make_constant_node("roi", onnx.TensorProto.FLOAT, (0,), []), + make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales), + ] + input_names = ["X", "roi", "scales"] + + # if scales == []: + # input_names.append("") + # else: + # input_names.append("scales") + # nodes.append(make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales)) + if oshape != []: + nodes.append( + make_constant_node("sizes", onnx.TensorProto.INT64, (len(oshape),), oshape) + ) + input_names.append("sizes") + nodes.append( + helper.make_node( + "Resize", + inputs=input_names, + outputs=["Y"], + mode=mode, + coordinate_transformation_mode=coord_trans, + cubic_coeff_a=alpha, + exclude_outside=exclude, + ) + ) + + if oshape == []: + oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] + graph = helper.make_graph( + nodes, + "resize_test", + inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], + outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], + ) + + model = helper.make_model(graph, producer_name="resize_test") + + verify_with_ort( + model, + [ishape], + [oshape], + use_vm=True, + opset=11, + freeze_params=True, + target=target, + dev=dev, + ) + + for ndim in [1, 2, 3]: + method = "nearest" + for coord_trans in ["asymmetric", "align_corners", "half_pixel"]: + # upsampling + verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method, coord_trans) + # downsampling + verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method, coord_trans) + # scales are specified instead of sizes + verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method, coord_trans) + verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method, coord_trans) + + method = "linear" + # upsampling + verify([1, 16] + [32] * ndim, [1, 16] + [64] * ndim, [], method) + # downsampling + verify([1, 16] + [32] * ndim, [1, 16] + [16] * ndim, [], method) + # scales are specified instead of sizes + verify([1, 16] + [32] * ndim, [], [1, 1] + [0.5] * ndim, method) + verify([1, 16] + [32] * ndim, [], [1, 1] + [2] * ndim, method) + + if ndim == 2: + # ONNX Runtime only supports cubic interpolation for 2D images + method = "cubic" + for alpha in [0.5, 0.75]: + for exclude in [True, False]: + # upsampling + verify( + [1, 16] + [32] * ndim, + [1, 16] + [64] * ndim, + [], + method, + alpha=alpha, + exclude=exclude, + ) + # downsampling + verify( + [1, 16] + [32] * ndim, + [1, 16] + [16] * ndim, + [], + method, + alpha=alpha, + exclude=exclude, + ) + # scales are specified instead of sizes + verify( + [1, 16] + [32] * ndim, + [], + [1, 1] + [0.5] * ndim, + method, + alpha=alpha, + exclude=exclude, + ) + verify( + [1, 16] + [32] * ndim, + [], + [1, 1] + [2] * ndim, + method, + alpha=alpha, + exclude=exclude, + ) + + def verify_opset_10(ishape, scales, mode): + nodes = [ + make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales), + ] + input_names = ["X", "scales"] + nodes.append( + helper.make_node( + "Resize", + inputs=input_names, + outputs=["Y"], + mode=mode, + ) + ) + + oshape = [round(dim * scale) for (dim, scale) in zip(ishape, scales)] + graph = helper.make_graph( + nodes, + "resize_test", + inputs=[helper.make_tensor_value_info("X", TensorProto.FLOAT, ishape)], + outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, oshape)], + ) + + model = helper.make_model(graph, producer_name="resize_test") + verify_with_ort( + model, + [ishape], + [oshape], + use_vm=True, + freeze_params=True, + opset=10, + target=target, + dev=dev, + ) + + verify_opset_10([1, 16, 32, 32], [1, 1, 2, 2], "nearest") + verify_opset_10([1, 16, 32, 32], [1, 1, 0.5, 0.5], "linear") @tvm.testing.parametrize_targets @@ -4958,16 +4960,7 @@ def verify_eyelike(indata): "test_reduce_sum_keepdims_random", "test_reduce_sum_negative_axes_keepdims_example", "test_reduce_sum_negative_axes_keepdims_random", - #"test_resize_downsample_sizes_cubic", - #"test_resize_downsample_sizes_linear_pytorch_half_pixel", - #"test_resize_downsample_sizes_nearest", "test_resize_tf_crop_and_resize", - "test_resize_downsample_sizes_nearest_tf_half_pixel_for_nn", - #"test_resize_upsample_sizes_cubic", - #"test_resize_upsample_sizes_nearest", - #"test_resize_upsample_sizes_nearest_ceil_half_pixel", - #"test_resize_upsample_sizes_nearest_floor_align_corners", - #"test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric", "test_rnn_seq_length", "test_round", "test_scan9_sum", From 3933e3850bcd2cde25cb67c65bf6c775a3c880ad Mon Sep 17 00:00:00 2001 From: CircleSpin Date: Wed, 13 Oct 2021 12:24:56 -0400 Subject: [PATCH 4/4] removed comments, adjusted for git review --- python/tvm/relay/frontend/onnx.py | 2 +- tests/python/frontend/onnx/test_forward.py | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 5ec038711110..5c112c7dfce0 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -2728,7 +2728,7 @@ def _impl_v13(cls, inputs, attr, params): def v11_13_common(cls, inputs, size, attr, params): """ Resize v11 and Resize v13 are identical except in how - they handle passing in scale and size. This utility + they handle the passing of scale and size. This utility provides the implementation for both """ ndims = len(infer_shape(inputs[0])) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 0a778ff2d67d..dd1c77330986 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -3971,11 +3971,6 @@ def verify(ishape, oshape, scales, mode, coord_trans="asymmetric", alpha=0.5, ex ] input_names = ["X", "roi", "scales"] - # if scales == []: - # input_names.append("") - # else: - # input_names.append("scales") - # nodes.append(make_constant_node("scales", onnx.TensorProto.FLOAT, (len(scales),), scales)) if oshape != []: nodes.append( make_constant_node("sizes", onnx.TensorProto.INT64, (len(oshape),), oshape)