diff --git a/ngraph/src/ngraph/frontend/onnx_import/op/resize.cpp b/ngraph/src/ngraph/frontend/onnx_import/op/resize.cpp index 2ec9cd6d994..e07ef5e5a33 100644 --- a/ngraph/src/ngraph/frontend/onnx_import/op/resize.cpp +++ b/ngraph/src/ngraph/frontend/onnx_import/op/resize.cpp @@ -18,6 +18,7 @@ #include "default_opset.hpp" #include "exceptions.hpp" #include "ngraph/op/util/op_types.hpp" +#include "utils/common.hpp" namespace ngraph { @@ -25,17 +26,49 @@ namespace ngraph { namespace op { - namespace set_1 + namespace { - NodeVector resize(const onnx_import::Node& node) + std::shared_ptr calculate_output_shape_based_on_scales( + const std::shared_ptr& data, + const std::shared_ptr& scales) { - const auto inputs = node.get_ng_inputs(); - const auto data = inputs.at(0); - const auto scales = inputs.at(1); + const auto& data_shape = data->get_output_partial_shape(0); + const auto& scales_shape = scales->get_output_partial_shape(0); - const auto data_shape = data->get_output_partial_shape(0); - const auto scales_shape = scales->get_output_partial_shape(0); + if (ngraph::op::is_constant(scales) && data_shape.is_static()) + { + const auto scales_const = + as_type_ptr(scales->shared_from_this()); + const auto scales_vector = scales_const->cast_vector(); + const auto data_static_shape = data_shape.to_shape(); + + std::vector output_shape; + for (size_t i = 0; i < data_static_shape.size(); ++i) + { + output_shape.push_back( + std::floor(data_static_shape.at(i) * scales_vector.at(i))); + } + auto output_shape_const = default_opset::Constant::create( + element::u64, Shape({output_shape.size()}), output_shape); + + return output_shape_const; + } + + const auto shape_of_data = std::make_shared( + std::make_shared(data), scales->get_element_type()); + const auto multiply = + std::make_shared(shape_of_data, scales); + const auto output_shape = + std::make_shared(multiply, ngraph::element::i64); + + return output_shape; + } + + NodeVector build_resize(const Node& node, + const std::shared_ptr& output_shape, + const AxisSet& axes) + { const auto mode = node.get_attribute_value("mode", "nearest"); std::unordered_set supported_modes = {"nearest", "linear"}; @@ -58,54 +91,123 @@ namespace ngraph supported_modes_str); } - CHECK_VALID_NODE( - node, - (scales_shape.is_static() || data_shape.rank().is_static()), - " Data rank or shape of Scales input is required to be static."); - - size_t axes_size = scales_shape.is_static() ? scales_shape.to_shape().at(0) - : data_shape.rank().get_length(); - AxisSet axes; - for (int ax = 0; ax < axes_size; ++ax) - { - axes.insert(ax); - } - auto attrs = ngraph::op::v0::InterpolateAttrs(); attrs.axes = axes; attrs.mode = mode; attrs.align_corners = false; - if (ngraph::op::is_constant(scales) && data_shape.is_static()) - { - const auto scales_const = - as_type_ptr(scales->shared_from_this()); + const auto inputs = node.get_ng_inputs(); + const auto& data = inputs.at(0); - auto scales_vector = scales_const->cast_vector(); - auto data_static_shape = data_shape.to_shape(); - - std::vector output_shape; - for (size_t i = 0; i < data_static_shape.size(); ++i) - { - output_shape.push_back( - std::floor(data_static_shape.at(i) * scales_vector.at(i))); - } - auto output_shape_const = default_opset::Constant::create( - element::u64, Shape({output_shape.size()}), output_shape); - - return {std::make_shared( - data, output_shape_const, attrs)}; - } - - auto shape_of_data = std::make_shared( - std::make_shared(data), ngraph::element::f32); - auto multiply = - std::make_shared(shape_of_data, scales); - auto output_shape = std::make_shared( - std::make_shared(multiply), ngraph::element::i64); return { std::make_shared(data, output_shape, attrs)}; } + } + + namespace set_11 + { + NodeVector resize(const onnx_import::Node& node) + { + // cubic_coeff_a, extrapolation_value attributes are ignored + // (they do not have influence on supported modes) + const auto coordinate_transformation_mode = + node.get_attribute_value("coordinate_transformation_mode", + "half_pixel"); + CHECK_VALID_NODE( + node, + coordinate_transformation_mode == "asymmetric", + coordinate_transformation_mode, + " - this type of coordinate transformation mode is not supported." + " Only asymmetric mode is supported by current version."); + + const auto exclude_outside = + node.get_attribute_value("exclude_outside ", 0); + CHECK_VALID_NODE(node, + exclude_outside == 0, + "Expected exclude_outside=", + exclude_outside, + " mode is not supported. ", + "Current version supports only exclude_outside equals `0`."); + + const auto mode = node.get_attribute_value("mode", "nearest"); + if (mode == "nearest") + { + const auto nearest_mode = node.get_attribute_value( + "nearest_mode", "round_prefer_floor"); + CHECK_VALID_NODE( + node, + nearest_mode == "floor", + "Expected nearest_mode=", + nearest_mode, + " mode is not supported. ", + "Current version support only nearest_mode equals `floor`"); + } + + // roi input (inputs.at(2)) is ignored because it is used only + // in "tf_crop_and_resize" which is not handled now + const auto inputs = node.get_ng_inputs(); + const auto& data = inputs.at(0); + const auto& data_shape = data->get_output_partial_shape(0); + + if (inputs.size() == 4) // sizes input is provided + { + const auto& sizes = inputs.at(3); + const auto& sizes_shape = sizes->get_output_partial_shape(0); + + CHECK_VALID_NODE( + node, + (sizes_shape.is_static() || data_shape.rank().is_static()), + " Data rank or shape of sizes input is required to be static."); + + size_t axes_size = sizes_shape.is_static() ? sizes_shape[0].get_length() + : data_shape.rank().get_length(); + + return build_resize( + node, sizes, AxisSet(common::get_monotonic_range(axes_size))); + } + + const auto& scales = inputs.at(2); + const auto& scales_shape = scales->get_output_partial_shape(0); + + CHECK_VALID_NODE( + node, + (scales_shape.is_static() || data_shape.rank().is_static()), + " Data rank or shape of scales input is required to be static."); + + size_t axes_size = scales_shape.is_static() ? scales_shape[0].get_length() + : data_shape.rank().get_length(); + + const auto output_shape = calculate_output_shape_based_on_scales(data, scales); + + return build_resize( + node, output_shape, AxisSet(common::get_monotonic_range(axes_size))); + } + } // namespace set_11 + + namespace set_1 + { + NodeVector resize(const onnx_import::Node& node) + { + const auto inputs = node.get_ng_inputs(); + const auto& data = inputs.at(0); + const auto& scales = inputs.at(1); + + const auto& data_shape = data->get_output_partial_shape(0); + const auto& scales_shape = scales->get_output_partial_shape(0); + + CHECK_VALID_NODE( + node, + (scales_shape.is_static() || data_shape.rank().is_static()), + " Data rank or shape of scales input is required to be static."); + + size_t axes_size = scales_shape.is_static() ? scales_shape[0].get_length() + : data_shape.rank().get_length(); + + const auto output_shape = calculate_output_shape_based_on_scales(data, scales); + + return build_resize( + node, output_shape, AxisSet(common::get_monotonic_range(axes_size))); + } } // namespace set_1 diff --git a/ngraph/src/ngraph/frontend/onnx_import/op/resize.hpp b/ngraph/src/ngraph/frontend/onnx_import/op/resize.hpp index eac27c400ae..41b7f90da0a 100644 --- a/ngraph/src/ngraph/frontend/onnx_import/op/resize.hpp +++ b/ngraph/src/ngraph/frontend/onnx_import/op/resize.hpp @@ -31,6 +31,11 @@ namespace ngraph } // namespace set_1 + namespace set_11 + { + NodeVector resize(const Node& node); + } + } // namespace op } // namespace onnx_import diff --git a/ngraph/src/ngraph/frontend/onnx_import/ops_bridge.cpp b/ngraph/src/ngraph/frontend/onnx_import/ops_bridge.cpp index b2dd277ca2b..3a1c92f69be 100644 --- a/ngraph/src/ngraph/frontend/onnx_import/ops_bridge.cpp +++ b/ngraph/src/ngraph/frontend/onnx_import/ops_bridge.cpp @@ -356,6 +356,7 @@ namespace ngraph REGISTER_OPERATOR("Relu", 1, relu); REGISTER_OPERATOR("Reshape", 1, reshape); REGISTER_OPERATOR("Resize", 1, resize); + REGISTER_OPERATOR("Resize", 11, resize); REGISTER_OPERATOR("ReverseSequence", 1, reverse_sequence); REGISTER_OPERATOR("RNN", 1, rnn); REGISTER_OPERATOR("RoiAlign", 1, roi_align); diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index 29968d51d0d..537443b4156 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -305,6 +305,7 @@ set(MULTI_TEST_SRC backend/gather.in.cpp backend/gelu.in.cpp backend/group_convolution.in.cpp + backend/interpolate.in.cpp backend/log.in.cpp backend/logical_or.in.cpp backend/logical_xor.in.cpp diff --git a/ngraph/test/backend/interpolate.in.cpp b/ngraph/test/backend/interpolate.in.cpp new file mode 100644 index 00000000000..98c37a99630 --- /dev/null +++ b/ngraph/test/backend/interpolate.in.cpp @@ -0,0 +1,62 @@ +//***************************************************************************** +// Copyright 2017-2020 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//***************************************************************************** + +#include "gtest/gtest.h" +#include "ngraph/ngraph.hpp" +#include "ngraph/runtime/tensor.hpp" +#include "runtime/backend.hpp" +#include "util/all_close.hpp" +#include "util/all_close_f.hpp" +#include "util/engine/test_engines.hpp" +#include "util/known_element_types.hpp" +#include "util/ndarray.hpp" +#include "util/test_case.hpp" +#include "util/test_control.hpp" +#include "util/test_tools.hpp" + +using namespace std; +using namespace ngraph; + +static string s_manifest = "${MANIFEST}"; + +using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME}); + +NGRAPH_TEST(${BACKEND_NAME}, interpolate_down_scales_const_linear) +{ + Shape input_shape{1, 1, 2, 4}; + Shape output_shape{1, 1, 1, 2}; + op::v0::InterpolateAttrs attrs; + attrs.axes = AxisSet{0, 1, 2, 3}; + attrs.mode = "linear"; + attrs.align_corners = false; + const auto input = make_shared(element::f32, input_shape); + const auto output_shape_input = op::Constant::create(element::i64, {4}, {1, 1, 1, 2}); + std::vector intput_data{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; + + auto interpolate = make_shared(input, output_shape_input, attrs); + auto f = make_shared(interpolate, ParameterVector{input}); + + auto backend = runtime::Backend::create("IE_CPU"); + auto input_tensor = backend->create_tensor(element::f32, input_shape); + auto result_tensor = backend->create_tensor(element::f32, output_shape); + auto handle = backend->compile(f); + copy_data(input_tensor, intput_data); + + handle->call_with_validate({result_tensor}, {input_tensor}); + + vector expected_output{1.0f, 2.66666651f}; + EXPECT_TRUE(test::all_close_f(expected_output, read_vector(result_tensor))); +} diff --git a/ngraph/test/models/onnx/resize11_scales_down_linear.prototxt b/ngraph/test/models/onnx/resize11_scales_down_linear.prototxt new file mode 100644 index 00000000000..b0e90078ffe --- /dev/null +++ b/ngraph/test/models/onnx/resize11_scales_down_linear.prototxt @@ -0,0 +1,124 @@ +ir_version: 7 +producer_name: "onnx-importer-test" +graph { + node { + output: "scales" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 4 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 0.6 + float_data: 0.6 + name: "const_tensor" + } + type: TENSOR + } + } + node { + output: "roi" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 8 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + name: "const_tensor" + } + type: TENSOR + } + } + node { + input: "X" + input: "roi" + input: "scales" + output: "Y" + op_type: "Resize" + attribute { + name: "coordinate_transformation_mode" + s: "asymmetric" + type: STRING + } + attribute { + name: "cubic_coeff_a" + f: -0.75 + type: FLOAT + } + attribute { + name: "exclude_outside" + i: 0 + type: INT + } + attribute { + name: "extrapolation_value" + f: 0 + type: FLOAT + } + attribute { + name: "mode" + s: "linear" + type: STRING + } + } + name: "test-model" + input { + name: "X" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + } + } + } + } + output { + name: "Y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + } + } + } + } +} +opset_import { + domain: "" + version: 11 +} + diff --git a/ngraph/test/models/onnx/resize11_scales_nearest_asymmetric_floor.prototxt b/ngraph/test/models/onnx/resize11_scales_nearest_asymmetric_floor.prototxt new file mode 100644 index 00000000000..f48e516a6a3 --- /dev/null +++ b/ngraph/test/models/onnx/resize11_scales_nearest_asymmetric_floor.prototxt @@ -0,0 +1,129 @@ +ir_version: 7 +producer_name: "onnx-importer-test" +graph { + node { + output: "scales" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 4 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 2.0 + float_data: 0.5 + name: "const_tensor" + } + type: TENSOR + } + } + node { + output: "roi" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 8 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + name: "const_tensor" + } + type: TENSOR + } + } + node { + input: "X" + input: "roi" + input: "scales" + output: "Y" + op_type: "Resize" + attribute { + name: "coordinate_transformation_mode" + s: "asymmetric" + type: STRING + } + attribute { + name: "cubic_coeff_a" + f: -0.75 + type: FLOAT + } + attribute { + name: "exclude_outside" + i: 0 + type: INT + } + attribute { + name: "extrapolation_value" + f: 0 + type: FLOAT + } + attribute { + name: "mode" + s: "nearest" + type: STRING + } + attribute { + name: "nearest_mode" + s: "floor" + type: STRING + } + } + name: "test-model" + input { + name: "X" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "Y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + dim { + dim_value: 1 + } + } + } + } + } +} +opset_import { + domain: "" + version: 11 +} + diff --git a/ngraph/test/models/onnx/resize11_scales_nearest_asymmetric_floor_dynamic_scales.prototxt b/ngraph/test/models/onnx/resize11_scales_nearest_asymmetric_floor_dynamic_scales.prototxt new file mode 100644 index 00000000000..3c837791fdd --- /dev/null +++ b/ngraph/test/models/onnx/resize11_scales_nearest_asymmetric_floor_dynamic_scales.prototxt @@ -0,0 +1,117 @@ +ir_version: 7 +producer_name: "onnx-importer-test" +graph { + node { + input: "X" + input: "roi" + input: "scales" + output: "Y" + op_type: "Resize" + attribute { + name: "coordinate_transformation_mode" + s: "asymmetric" + type: STRING + } + attribute { + name: "cubic_coeff_a" + f: -0.75 + type: FLOAT + } + attribute { + name: "exclude_outside" + i: 0 + type: INT + } + attribute { + name: "extrapolation_value" + f: 0 + type: FLOAT + } + attribute { + name: "mode" + s: "nearest" + type: STRING + } + attribute { + name: "nearest_mode" + s: "floor" + type: STRING + } + } + name: "test-model" + input { + name: "X" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + input { + name: "roi" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 8 + } + } + } + } + } + input { + name: "scales" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 4 + } + } + } + } + } + output { + name: "Y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + dim { + dim_value: 1 + } + } + } + } + } +} +opset_import { + domain: "" + version: 11 +} + diff --git a/ngraph/test/models/onnx/resize11_scales_up_linear_asymmetric.prototxt b/ngraph/test/models/onnx/resize11_scales_up_linear_asymmetric.prototxt new file mode 100644 index 00000000000..9a0a7ded8d6 --- /dev/null +++ b/ngraph/test/models/onnx/resize11_scales_up_linear_asymmetric.prototxt @@ -0,0 +1,129 @@ +ir_version: 7 +producer_name: "onnx-importer-test" +graph { + node { + output: "scales" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 4 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 2.0 + float_data: 4.0 + name: "const_tensor" + } + type: TENSOR + } + } + node { + output: "roi" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 8 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + name: "const_tensor" + } + type: TENSOR + } + } + node { + input: "X" + input: "roi" + input: "scales" + output: "Y" + op_type: "Resize" + attribute { + name: "coordinate_transformation_mode" + s: "asymmetric" + type: STRING + } + attribute { + name: "cubic_coeff_a" + f: -0.75 + type: FLOAT + } + attribute { + name: "exclude_outside" + i: 0 + type: INT + } + attribute { + name: "extrapolation_value" + f: 0 + type: FLOAT + } + attribute { + name: "mode" + s: "linear" + type: STRING + } + attribute { + name: "nearest_mode" + s: "floor" + type: STRING + } + } + name: "test-model" + input { + name: "X" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "Y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + dim { + dim_value: 8 + } + } + } + } + } +} +opset_import { + domain: "" + version: 11 +} + diff --git a/ngraph/test/models/onnx/resize11_sizes_linear.prototxt b/ngraph/test/models/onnx/resize11_sizes_linear.prototxt new file mode 100644 index 00000000000..6de38295973 --- /dev/null +++ b/ngraph/test/models/onnx/resize11_sizes_linear.prototxt @@ -0,0 +1,139 @@ +ir_version: 7 +producer_name: "onnx-importer-test" +graph { + node { + output: "scales" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 1 + float_data: 1.0 + data_type: 1 + name: "const_tensor" + } + type: TENSOR + } + } + node { + output: "sizes" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 4 + data_type: 7 + int64_data: 2 + int64_data: 1 + int64_data: 4 + int64_data: 8 + name: "const_tensor" + } + type: TENSOR + } + } + node { + output: "roi" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 8 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + name: "const_tensor" + } + type: TENSOR + } + } + node { + input: "X" + input: "roi" + input: "scales" + input: "sizes" + output: "Y" + op_type: "Resize" + attribute { + name: "coordinate_transformation_mode" + s: "asymmetric" + type: STRING + } + attribute { + name: "cubic_coeff_a" + f: -0.75 + type: FLOAT + } + attribute { + name: "exclude_outside" + i: 0 + type: INT + } + attribute { + name: "extrapolation_value" + f: 0 + type: FLOAT + } + attribute { + name: "mode" + s: "linear" + type: STRING + } + } + name: "test-model" + input { + name: "X" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "Y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + dim { + dim_value: 8 + } + } + } + } + } +} +opset_import { + domain: "" + version: 11 +} + diff --git a/ngraph/test/models/onnx/resize11_sizes_nearest_asymmetric_floor.prototxt b/ngraph/test/models/onnx/resize11_sizes_nearest_asymmetric_floor.prototxt new file mode 100644 index 00000000000..f3ce3308c0d --- /dev/null +++ b/ngraph/test/models/onnx/resize11_sizes_nearest_asymmetric_floor.prototxt @@ -0,0 +1,144 @@ +ir_version: 7 +producer_name: "onnx-importer-test" +graph { + node { + output: "scales" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 1 + float_data: 1.0 + data_type: 1 + name: "const_tensor" + } + type: TENSOR + } + } + node { + output: "sizes" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 4 + data_type: 7 + int64_data: 2 + int64_data: 1 + int64_data: 4 + int64_data: 1 + name: "const_tensor" + } + type: TENSOR + } + } + node { + output: "roi" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 8 + data_type: 1 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + float_data: 1.0 + name: "const_tensor" + } + type: TENSOR + } + } + node { + input: "X" + input: "roi" + input: "scales" + input: "sizes" + output: "Y" + op_type: "Resize" + attribute { + name: "coordinate_transformation_mode" + s: "asymmetric" + type: STRING + } + attribute { + name: "cubic_coeff_a" + f: -0.75 + type: FLOAT + } + attribute { + name: "exclude_outside" + i: 0 + type: INT + } + attribute { + name: "extrapolation_value" + f: 0 + type: FLOAT + } + attribute { + name: "mode" + s: "nearest" + type: STRING + } + attribute { + name: "nearest_mode" + s: "floor" + type: STRING + } + } + name: "test-model" + input { + name: "X" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "Y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + dim { + dim_value: 4 + } + dim { + dim_value: 1 + } + } + } + } + } +} +opset_import { + domain: "" + version: 11 +} + diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index 6d475608f82..c989856c1bf 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -1148,6 +1148,113 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_resize10_up_scales_const_nearest) test_case.run(); } +NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_down_linear) +{ + const auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_scales_down_linear.prototxt")); + + const Shape expected_output_shape{1, 1, 1, 2}; + auto test_case = test::TestCase(function); + const size_t input_size = 8; + std::vector input_data(input_size); + std::iota(std::begin(input_data), std::end(input_data), 1.0f); + test_case.add_input(input_data); + test_case.add_expected_output(expected_output_shape, {1.0f, 2.66666651f}); + + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_up_linear_asymmetric) +{ + const auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_scales_up_linear_asymmetric.prototxt")); + + const Shape expected_output_shape{2, 1, 4, 8}; + auto test_case = test::TestCase(function); + const size_t input_size = 8; + std::vector input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f}; + test_case.add_input(input_data); + test_case.add_expected_output( + expected_output_shape, + {1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 2.5f, 3.25f, 4.0f, + 4.75f, 5.5f, 5.5f, 5.5f, 5.5f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 8.0f, + 8.0f, 8.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 8.0f, 8.0f, 8.0f, + + 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 2.0f, 2.0f, 2.0f, 6.5f, 6.5f, 6.5f, + 6.5f, 6.5f, 6.5f, 6.5f, 6.5f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f, + 11.0f, 11.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 11.0f, 11.0f, 11.0f}); + + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_nearest_asymmetric_floor) +{ + const auto function = onnx_import::import_onnx_model(file_util::path_join( + SERIALIZED_ZOO, "onnx/resize11_scales_nearest_asymmetric_floor.prototxt")); + + const Shape expected_output_shape{2, 1, 4, 1}; + auto test_case = test::TestCase(function); + const std::vector input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f}; + test_case.add_input(input_data); + test_case.add_expected_output(expected_output_shape, + {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f}); + + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_scales_nearest_asymmetric_floor_dynamic_sizes) +{ + const auto function = onnx_import::import_onnx_model(file_util::path_join( + SERIALIZED_ZOO, "onnx/resize11_scales_nearest_asymmetric_floor_dynamic_scales.prototxt")); + + const Shape expected_output_shape{2, 1, 4, 1}; + auto test_case = test::TestCase(function); + const std::vector input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f}; + test_case.add_input(input_data); + test_case.add_input( + std::vector{1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}); // roi + test_case.add_input(std::vector{1.0f, 1.0f, 2.0f, 0.5f}); // scales + test_case.add_expected_output(expected_output_shape, + {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f}); + + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_sizes_nearest_asymmetric_floor) +{ + const auto function = onnx_import::import_onnx_model(file_util::path_join( + SERIALIZED_ZOO, "onnx/resize11_sizes_nearest_asymmetric_floor.prototxt")); + + const Shape expected_output_shape{2, 1, 4, 1}; + auto test_case = test::TestCase(function); + std::vector input_data{1.0f, 3.0f, 4.0f, 8.0f, 6.0f, 2.0f, 7.0f, 11.0f}; + test_case.add_input(input_data); + test_case.add_expected_output(expected_output_shape, + {1.0f, 1.0f, 4.0f, 4.0f, 6.0f, 6.0f, 7.0f, 7.0f}); + + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_resize11_sizes_linear) +{ + const auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/resize11_sizes_linear.prototxt")); + + const Shape expected_output_shape{2, 1, 4, 8}; + auto test_case = test::TestCase(function); + std::vector input_data{2.0f, 4.0f, 1.0f, 3.0f, 7.0f, 8.0f, 9.0f, 6.0f}; + test_case.add_input(input_data); + test_case.add_expected_output( + expected_output_shape, + {2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.0f, 4.0f, 4.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, + 3.5f, 3.5f, 3.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 1.0f, 1.5f, + 2.0f, 2.5f, 3.0f, 3.0f, 3.0f, 3.0f, 7.0f, 7.25f, 7.5f, 7.75f, 8.0f, 8.0f, 8.0f, + 8.0f, 8.0f, 7.75f, 7.5f, 7.25f, 7.0f, 7.0f, 7.0f, 7.0f, 9.0f, 8.25f, 7.5f, 6.75f, + 6.0f, 6.0f, 6.0f, 6.0f, 9.0f, 8.25f, 7.5f, 6.75f, 6.0f, 6.0f, 6.0f, 6.0f}); + + test_case.run(); +} + NGRAPH_TEST(${BACKEND_NAME}, onnx_model_shape) { auto function = diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 266607c43e6..fd4ccd3bcec 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -1087,8 +1087,17 @@ IE_CPU.atanh IE_CPU.asinh IE_CPU.acosh +# Interpolate-1 in linear mode +# 2.666666507720947266 is not close to 3 at index 1 +IE_CPU.interpolate_down_scales_const_linear + # Result mismatch 2.666666507720947266 is not close to 3 at index 1 IE_CPU.onnx_resize10_down_scales_const_linear +IE_CPU.onnx_resize11_scales_down_linear + +# C++ exception with description "Interpolate operation should be converted to Interp +# not constant output_shape passed to Interpolate-1 +IE_CPU.onnx_resize11_scales_nearest_asymmetric_floor_dynamic_sizes # GRUCell operation has a form that is not supported IE_CPU.onnx_model_gru_defaults_fwd diff --git a/ngraph/test/runtime/interpreter/unit_test.manifest b/ngraph/test/runtime/interpreter/unit_test.manifest index af169828f10..ec725980bfe 100644 --- a/ngraph/test/runtime/interpreter/unit_test.manifest +++ b/ngraph/test/runtime/interpreter/unit_test.manifest @@ -20,6 +20,13 @@ INTERPRETER.onnx_upsample8_linear_infer INTERPRETER.onnx_upsample9_scales_const_nearest_infer INTERPRETER.onnx_upsample9_scales_const_linear_infer INTERPRETER.onnx_upsample9_scales_input_nearest_infer +INTERPRETER.onnx_resize11_scales_down_linear +INTERPRETER.onnx_resize11_scales_up_linear_asymmetric +INTERPRETER.onnx_resize11_scales_nearest_asymmetric_floor +INTERPRETER.onnx_resize11_sizes_nearest_asymmetric_floor +INTERPRETER.onnx_resize11_sizes_linear +INTERPRETER.onnx_resize11_scales_nearest_asymmetric_floor_dynamic_sizes +INTERPRETER.interpolate_down_scales_const_linear # ONNX Loop onnx_controlflow_loop_2d_add_execution