From b23cc04f347e99d57b7567cae663ad5585920e2c Mon Sep 17 00:00:00 2001 From: Ashwini Khade Date: Mon, 21 Oct 2019 23:28:43 -0700 Subject: [PATCH] Handle the case when scales is constant but size is 0 (#2218) --- .../core/providers/cpu/tensor/upsample.h | 4 +-- .../providers/cpu/tensor/resize_op_test.cc | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/cpu/tensor/upsample.h b/onnxruntime/core/providers/cpu/tensor/upsample.h index 0f716b2bd0..32594cbcfc 100644 --- a/onnxruntime/core/providers/cpu/tensor/upsample.h +++ b/onnxruntime/core/providers/cpu/tensor/upsample.h @@ -79,7 +79,7 @@ class UpsampleBase { const Tensor* scale; bool get_scale = info.TryGetConstantInput(scales_input_idx_, &scale); - if (get_scale) { + if (get_scale&& scale->Shape().Size() > 0) { ParseScalesData(scale, scales_); scales_cached_ = true; } @@ -214,7 +214,7 @@ class UpsampleBase { } } - if (UpsampleMode::LINEAR == mode) { + if (UpsampleMode::LINEAR == mode || UpsampleMode::CUBIC == mode) { ORT_ENFORCE(scales.size() == 2 || (scales.size() == 4 && scales[0] == 1 && scales[1] == 1), "'Linear' mode only support 2-D inputs ('Bilinear') or 4-D inputs " "with the corresponding outermost 2 scale values being 1 in the ", diff --git a/onnxruntime/test/providers/cpu/tensor/resize_op_test.cc b/onnxruntime/test/providers/cpu/tensor/resize_op_test.cc index 4325ddb259..8870c5040c 100644 --- a/onnxruntime/test/providers/cpu/tensor/resize_op_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/resize_op_test.cc @@ -441,6 +441,36 @@ TEST(ResizeOpTest, ResizeOpCubicDownSampleTest) { test.Run(); } +TEST(ResizeOpTest, ResizeOpLineartDownSampleTest_exclude_outside) { + OpTester test("Resize", 11); + std::vector roi{}; + std::vector scales{0.8f, 0.8f}; + std::vector sizes{}; + + test.AddAttribute("mode", "cubic"); + test.AddAttribute("exclude_outside", static_cast(1)); + test.AddAttribute("cubic_coeff_a", -0.5f); + + const int64_t H = 4, W = 4; + + std::vector X = { + 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f}; + + test.AddInput("X", {H, W}, X); + test.AddInput("roi", {0}, roi); + test.AddInput("scales", {2}, scales); + + std::vector Y = {1.36813f, 2.6695f, 4.01334f, + 6.57363f, 7.875f, 9.21884f, + 11.949f, 13.2503f, 14.5942f}; + + test.AddOutput("Y", {(int64_t)(H * scales[0]), (int64_t)(W * scales[1])}, Y); + test.Run(); +} + TEST(ResizeOpTest, ResizeOpCubicDownSampleTest_coeff) { OpTester test("Resize", 11); std::vector scales{1.0f, 1.0f, 0.8f, 0.8f};