From f9db1e6da09fc1d85f0d8b2fb5371c4a53cd0239 Mon Sep 17 00:00:00 2001 From: bsledz Date: Fri, 5 Feb 2021 12:07:50 +0100 Subject: [PATCH 01/13] Add support for custom ONNX operator PriorBoxClustered --- .../prior_box_clustered.cpp | 74 ++++++++++ .../prior_box_clustered.hpp | 38 +++++ .../frontend/onnx_import/src/ops_bridge.cpp | 2 + .../models/onnx/priorbox_clustered.prototxt | 88 ++++++++++++ ...clustered_input_shape_as_constant.prototxt | 90 ++++++++++++ ngraph/test/onnx/onnx_import.in.cpp | 131 ++++++++++++++++++ 6 files changed, 423 insertions(+) create mode 100644 ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp create mode 100644 ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp create mode 100644 ngraph/test/models/onnx/priorbox_clustered.prototxt create mode 100644 ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp new file mode 100644 index 00000000000000..bbd93ed154c3df --- /dev/null +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp @@ -0,0 +1,74 @@ +//***************************************************************************** +// Copyright 2017-2021 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 "ngraph/op/prior_box_clustered.hpp" +#include "default_opset.hpp" +#include "ngraph/node.hpp" +#include "onnx_import/core/node.hpp" +#include "op/org.openvinotoolkit/prior_box_clustered.hpp" + +namespace ngraph +{ + namespace onnx_import + { + namespace op + { + namespace set_1 + { + OutputVector prior_box_clustered(const Node& node) + { + using PriorBoxClustered = default_opset::PriorBoxClustered; + + auto inputs = node.get_ng_inputs(); + auto layer_shape = inputs[0]; + auto img_shape = inputs[1]; + + ngraph::op::PriorBoxClusteredAttrs attrs{}; + attrs.widths = + node.get_attribute_value>("width", {1.0}); + attrs.heights = + node.get_attribute_value>("height", {1.0}); + // attrs.flip = + // node.get_attribute_value("flip", 0); + attrs.clip = + node.get_attribute_value("clip", 0); + attrs.variances = + node.get_attribute_value>("variance", {0.1f}); + // attrs.img_size = + // node.get_attribute_value("img_size", 0); + // attrs.img_h = + // node.get_attribute_value("img_h", 0); + // attrs.img_w = + // node.get_attribute_value("img_w", 0); + // attrs.step = + // node.get_attribute_value("step", 0.0f); + attrs.step_heights = + node.get_attribute_value("step_h", 0.0f); + attrs.step_widths = + node.get_attribute_value("step_w", 0.0f); + attrs.offset = + node.get_attribute_value("offset", 0.0f); + + return {std::make_shared(layer_shape, img_shape, attrs)}; + } + + } // namespace set_1 + + } // namespace op + + } // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp new file mode 100644 index 00000000000000..aa6ac010419f7c --- /dev/null +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp @@ -0,0 +1,38 @@ +//***************************************************************************** +// Copyright 2017-2021 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. +//***************************************************************************** + +#pragma once + +#include "ngraph/node.hpp" +#include "onnx_import/core/node.hpp" + +namespace ngraph +{ + namespace onnx_import + { + namespace op + { + namespace set_1 + { + OutputVector prior_box_clustered(const Node& node); + + } // namespace set_1 + + } // namespace op + + } // namespace onnx_import + +} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/ops_bridge.cpp b/ngraph/frontend/onnx_import/src/ops_bridge.cpp index e19098c3d6d5d3..359d8a8a6075b0 100644 --- a/ngraph/frontend/onnx_import/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx_import/src/ops_bridge.cpp @@ -149,6 +149,7 @@ #include "op/org.openvinotoolkit/group_norm.hpp" #include "op/org.openvinotoolkit/normalize.hpp" #include "op/org.openvinotoolkit/prior_box.hpp" +#include "op/org.openvinotoolkit/prior_box_clustered.hpp" #include "op/org.openvinotoolkit/swish.hpp" namespace ngraph @@ -466,6 +467,7 @@ namespace ngraph REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "GroupNorm", 1, group_norm); REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "Normalize", 1, normalize); REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "PriorBox", 1, prior_box); + REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "PriorBoxClustered", 1, prior_box_clustered); REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "Swish", 1, swish); } diff --git a/ngraph/test/models/onnx/priorbox_clustered.prototxt b/ngraph/test/models/onnx/priorbox_clustered.prototxt new file mode 100644 index 00000000000000..4440fa6dfb81f2 --- /dev/null +++ b/ngraph/test/models/onnx/priorbox_clustered.prototxt @@ -0,0 +1,88 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + domain: "org.openvinotoolkit" + input: "input_shape" + input: "image_shape" + output: "out" + op_type: "PriorBoxClustered" + attribute { + name: "width" + floats: 2.12 + floats: 1.6 + type: FLOATS + } + attribute { + name: "height" + floats: 5.12 + floats: 5.6 + type: FLOATS + } + attribute { + name: "step_w" + f: 0.0 + type: FLOAT + } + attribute { + name: "step_h" + f: 0.0 + type: FLOAT + } + attribute { + name: "offset" + f: 0.5 + type: FLOAT + } + attribute { + name: "variances" + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + } + name: "compute_graph" + input { + name: "input_shape" + type { + tensor_type { + elem_type: 7 + shape { + dim { + dim_value: 2 + } + } + } + } + } + input { + name: "image_shape" + type { + tensor_type { + elem_type: 7 + shape { + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "out" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt b/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt new file mode 100644 index 00000000000000..1937033ebe94d0 --- /dev/null +++ b/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt @@ -0,0 +1,90 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + output: "input_shape" + op_type: "Constant" + attribute { + name: "value" + t { + dims: 2 + data_type: 7 + int64_data: 2 + int64_data: 2 + name: "const_tensor" + } + type: TENSOR + } + } + node { + domain: "org.openvinotoolkit" + input: "input_shape" + input: "image_shape" + output: "out" + op_type: "PriorBoxClustered" + attribute { + name: "width" + floats: 2.12 + floats: 1.6 + type: FLOATS + } + attribute { + name: "height" + floats: 5.12 + floats: 5.6 + type: FLOATS + } + attribute { + name: "step_w" + f: 0.0 + type: FLOAT + } + attribute { + name: "step_h" + f: 0.0 + type: FLOAT + } + attribute { + name: "offset" + f: 0.5 + type: FLOAT + } + attribute { + name: "variances" + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + } + name: "compute_graph" + input { + name: "image_shape" + type { + tensor_type { + elem_type: 7 + shape { + dim { + dim_value: 2 + } + } + } + } + } + output { + name: "out" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index 475a1bba3328eb..aaabf7c641644e 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -3970,3 +3970,134 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_mvn_v6) 1.2906139, 1.1860244, -0.92945826, 0.0721334, -0.38174, -1.7799333}); test_case.run(); } + +NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered) +{ + auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/priorbox_clustered.prototxt")); + + auto test_case = test::TestCase(function); + test_case.add_input( + {2, 2}); + + test_case.add_input( + {5, 5}); + test_case.add_expected_output( + Shape{2, 32}, + {0.03800000995397567749, -0.2619999945163726807, 0.4619999825954437256, 0.761999964714050293, 0.0899999961256980896, -0.310000002384185791, + 0.4099999964237213135, 0.8100000619888305664, 0.5379999876022338867, -0.2619999945163726807, 0.9620000123977661133, 0.761999964714050293, + 0.5900000333786010742, -0.310000002384185791, 0.9100000262260437012, 0.8100000619888305664, 0.03800000995397567749, + 0.2380000054836273193, +0.4619999825954437256, +1.261999964714050293, +0.0899999961256980896, +0.1900000125169754028, +0.4099999964237213135, +1.310000061988830566, +0.5379999876022338867, +0.2380000054836273193, +0.9620000123977661133, +1.261999964714050293, +0.5900000333786010742, +0.1900000125169754028, +0.9100000262260437012, +1.310000061988830566, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +}); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_input_shape_as_constant) +{ + auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/priorbox_clustered_input_shape_as_constant.prototxt")); + + auto test_case = test::TestCase(function); + test_case.add_input( + {5, 5}); + test_case.add_expected_output( + Shape{2, 32}, + {0.03800000995397567749, -0.2619999945163726807, 0.4619999825954437256, 0.761999964714050293, 0.0899999961256980896, -0.310000002384185791, + 0.4099999964237213135, 0.8100000619888305664, 0.5379999876022338867, -0.2619999945163726807, 0.9620000123977661133, 0.761999964714050293, + 0.5900000333786010742, -0.310000002384185791, 0.9100000262260437012, 0.8100000619888305664, 0.03800000995397567749, + 0.2380000054836273193, +0.4619999825954437256, +1.261999964714050293, +0.0899999961256980896, +0.1900000125169754028, +0.4099999964237213135, +1.310000061988830566, +0.5379999876022338867, +0.2380000054836273193, +0.9620000123977661133, +1.261999964714050293, +0.5900000333786010742, +0.1900000125169754028, +0.9100000262260437012, +1.310000061988830566, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.1000000014901161194, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +0.0f, +}); + test_case.run(); +} From b3f48e157e6831c7f443340c63e2327c72f3213f Mon Sep 17 00:00:00 2001 From: bsledz Date: Fri, 5 Feb 2021 13:38:55 +0100 Subject: [PATCH 02/13] Fix codestyle --- .../prior_box_clustered.cpp | 20 +- .../frontend/onnx_import/src/ops_bridge.cpp | 3 +- ngraph/test/onnx/onnx_import.in.cpp | 255 ++++++++++-------- 3 files changed, 149 insertions(+), 129 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp index bbd93ed154c3df..fcf0584b524c9d 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp @@ -37,14 +37,11 @@ namespace ngraph auto img_shape = inputs[1]; ngraph::op::PriorBoxClusteredAttrs attrs{}; - attrs.widths = - node.get_attribute_value>("width", {1.0}); - attrs.heights = - node.get_attribute_value>("height", {1.0}); + attrs.widths = node.get_attribute_value>("width", {1.0}); + attrs.heights = node.get_attribute_value>("height", {1.0}); // attrs.flip = - // node.get_attribute_value("flip", 0); - attrs.clip = - node.get_attribute_value("clip", 0); + // node.get_attribute_value("flip", 0); + attrs.clip = node.get_attribute_value("clip", 0); attrs.variances = node.get_attribute_value>("variance", {0.1f}); // attrs.img_size = @@ -55,12 +52,9 @@ namespace ngraph // node.get_attribute_value("img_w", 0); // attrs.step = // node.get_attribute_value("step", 0.0f); - attrs.step_heights = - node.get_attribute_value("step_h", 0.0f); - attrs.step_widths = - node.get_attribute_value("step_w", 0.0f); - attrs.offset = - node.get_attribute_value("offset", 0.0f); + attrs.step_heights = node.get_attribute_value("step_h", 0.0f); + attrs.step_widths = node.get_attribute_value("step_w", 0.0f); + attrs.offset = node.get_attribute_value("offset", 0.0f); return {std::make_shared(layer_shape, img_shape, attrs)}; } diff --git a/ngraph/frontend/onnx_import/src/ops_bridge.cpp b/ngraph/frontend/onnx_import/src/ops_bridge.cpp index 359d8a8a6075b0..6ea492ded80de9 100644 --- a/ngraph/frontend/onnx_import/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx_import/src/ops_bridge.cpp @@ -467,7 +467,8 @@ namespace ngraph REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "GroupNorm", 1, group_norm); REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "Normalize", 1, normalize); REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "PriorBox", 1, prior_box); - REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "PriorBoxClustered", 1, prior_box_clustered); + REGISTER_OPERATOR_WITH_DOMAIN( + OPENVINO_ONNX_DOMAIN, "PriorBoxClustered", 1, prior_box_clustered); REGISTER_OPERATOR_WITH_DOMAIN(OPENVINO_ONNX_DOMAIN, "Swish", 1, swish); } diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index aaabf7c641644e..8aaaa017d8d01d 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -3977,127 +3977,152 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered) file_util::path_join(SERIALIZED_ZOO, "onnx/priorbox_clustered.prototxt")); auto test_case = test::TestCase(function); - test_case.add_input( - {2, 2}); - - test_case.add_input( - {5, 5}); - test_case.add_expected_output( - Shape{2, 32}, - {0.03800000995397567749, -0.2619999945163726807, 0.4619999825954437256, 0.761999964714050293, 0.0899999961256980896, -0.310000002384185791, - 0.4099999964237213135, 0.8100000619888305664, 0.5379999876022338867, -0.2619999945163726807, 0.9620000123977661133, 0.761999964714050293, - 0.5900000333786010742, -0.310000002384185791, 0.9100000262260437012, 0.8100000619888305664, 0.03800000995397567749, - 0.2380000054836273193, -0.4619999825954437256, -1.261999964714050293, -0.0899999961256980896, -0.1900000125169754028, -0.4099999964237213135, -1.310000061988830566, -0.5379999876022338867, -0.2380000054836273193, -0.9620000123977661133, -1.261999964714050293, -0.5900000333786010742, -0.1900000125169754028, -0.9100000262260437012, -1.310000061988830566, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -}); + test_case.add_input({2, 2}); + + test_case.add_input({5, 5}); + test_case.add_expected_output(Shape{2, 32}, + { + 0.03800000995397567749, + -0.2619999945163726807, + 0.4619999825954437256, + 0.761999964714050293, + 0.0899999961256980896, + -0.310000002384185791, + 0.4099999964237213135, + 0.8100000619888305664, + 0.5379999876022338867, + -0.2619999945163726807, + 0.9620000123977661133, + 0.761999964714050293, + 0.5900000333786010742, + -0.310000002384185791, + 0.9100000262260437012, + 0.8100000619888305664, + 0.03800000995397567749, + 0.2380000054836273193, + 0.4619999825954437256, + 1.261999964714050293, + 0.0899999961256980896, + 0.1900000125169754028, + 0.4099999964237213135, + 1.310000061988830566, + 0.5379999876022338867, + 0.2380000054836273193, + 0.9620000123977661133, + 1.261999964714050293, + 0.5900000333786010742, + 0.1900000125169754028, + 0.9100000262260437012, + 1.310000061988830566, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + }); test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_input_shape_as_constant) { - auto function = onnx_import::import_onnx_model( - file_util::path_join(SERIALIZED_ZOO, "onnx/priorbox_clustered_input_shape_as_constant.prototxt")); + auto function = onnx_import::import_onnx_model(file_util::path_join( + SERIALIZED_ZOO, "onnx/priorbox_clustered_input_shape_as_constant.prototxt")); auto test_case = test::TestCase(function); - test_case.add_input( - {5, 5}); - test_case.add_expected_output( - Shape{2, 32}, - {0.03800000995397567749, -0.2619999945163726807, 0.4619999825954437256, 0.761999964714050293, 0.0899999961256980896, -0.310000002384185791, - 0.4099999964237213135, 0.8100000619888305664, 0.5379999876022338867, -0.2619999945163726807, 0.9620000123977661133, 0.761999964714050293, - 0.5900000333786010742, -0.310000002384185791, 0.9100000262260437012, 0.8100000619888305664, 0.03800000995397567749, - 0.2380000054836273193, -0.4619999825954437256, -1.261999964714050293, -0.0899999961256980896, -0.1900000125169754028, -0.4099999964237213135, -1.310000061988830566, -0.5379999876022338867, -0.2380000054836273193, -0.9620000123977661133, -1.261999964714050293, -0.5900000333786010742, -0.1900000125169754028, -0.9100000262260437012, -1.310000061988830566, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.1000000014901161194, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -0.0f, -}); + test_case.add_input({5, 5}); + test_case.add_expected_output(Shape{2, 32}, + { + 0.03800000995397567749, + -0.2619999945163726807, + 0.4619999825954437256, + 0.761999964714050293, + 0.0899999961256980896, + -0.310000002384185791, + 0.4099999964237213135, + 0.8100000619888305664, + 0.5379999876022338867, + -0.2619999945163726807, + 0.9620000123977661133, + 0.761999964714050293, + 0.5900000333786010742, + -0.310000002384185791, + 0.9100000262260437012, + 0.8100000619888305664, + 0.03800000995397567749, + 0.2380000054836273193, + 0.4619999825954437256, + 1.261999964714050293, + 0.0899999961256980896, + 0.1900000125169754028, + 0.4099999964237213135, + 1.310000061988830566, + 0.5379999876022338867, + 0.2380000054836273193, + 0.9620000123977661133, + 1.261999964714050293, + 0.5900000333786010742, + 0.1900000125169754028, + 0.9100000262260437012, + 1.310000061988830566, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.1000000014901161194, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + 0.0f, + }); test_case.run(); } From ff9263f2ba56141471b3bd996d3b5e2e1ab29724 Mon Sep 17 00:00:00 2001 From: bsledz Date: Mon, 8 Feb 2021 12:40:53 +0100 Subject: [PATCH 03/13] Add unittest for constant input --- ...clustered_input_shape_as_constant.prototxt | 32 ++-- ngraph/test/onnx/onnx_import.in.cpp | 142 +++++++----------- 2 files changed, 71 insertions(+), 103 deletions(-) diff --git a/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt b/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt index 1937033ebe94d0..70264e7ee7ff02 100644 --- a/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt +++ b/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt @@ -9,8 +9,8 @@ graph { t { dims: 2 data_type: 7 - int64_data: 2 - int64_data: 2 + int64_data: 1 + int64_data: 1 name: "const_tensor" } type: TENSOR @@ -24,36 +24,44 @@ graph { op_type: "PriorBoxClustered" attribute { name: "width" - floats: 2.12 - floats: 1.6 + floats: 128 + floats: 512 + floats: 4096 type: FLOATS } attribute { name: "height" - floats: 5.12 - floats: 5.6 + floats: 128 + floats: 512 + floats: 4096 type: FLOATS } attribute { name: "step_w" - f: 0.0 + f: 0.77 type: FLOAT } attribute { name: "step_h" - f: 0.0 + f: 1.55 type: FLOAT } attribute { name: "offset" - f: 0.5 + f: 1 type: FLOAT } + attribute { + name: "clip" + i: 1 + type: INT + } attribute { name: "variances" - floats: 0.1 - floats: 0.2 - floats: 0.2 + floats: 1.33 + floats: 2.44 + floats: 0.44 + floats: 2.44 type: FLOATS } } diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index 8aaaa017d8d01d..8667f8dc9c5e2c 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -3982,46 +3982,46 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered) test_case.add_input({5, 5}); test_case.add_expected_output(Shape{2, 32}, { - 0.03800000995397567749, - -0.2619999945163726807, - 0.4619999825954437256, - 0.761999964714050293, - 0.0899999961256980896, - -0.310000002384185791, - 0.4099999964237213135, - 0.8100000619888305664, - 0.5379999876022338867, - -0.2619999945163726807, - 0.9620000123977661133, - 0.761999964714050293, - 0.5900000333786010742, - -0.310000002384185791, - 0.9100000262260437012, - 0.8100000619888305664, - 0.03800000995397567749, - 0.2380000054836273193, - 0.4619999825954437256, - 1.261999964714050293, - 0.0899999961256980896, - 0.1900000125169754028, - 0.4099999964237213135, - 1.310000061988830566, - 0.5379999876022338867, - 0.2380000054836273193, - 0.9620000123977661133, - 1.261999964714050293, - 0.5900000333786010742, - 0.1900000125169754028, - 0.9100000262260437012, - 1.310000061988830566, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, + 0.03800000995397567749f, + -0.2619999945163726807f, + 0.4619999825954437256f, + 0.761999964714050293f, + 0.0899999961256980896f, + -0.310000002384185791f, + 0.4099999964237213135f, + 0.8100000619888305664f, + 0.5379999876022338867f, + -0.2619999945163726807f, + 0.9620000123977661133f, + 0.761999964714050293f, + 0.5900000333786010742f, + -0.310000002384185791f, + 0.9100000262260437012f, + 0.8100000619888305664f, + 0.03800000995397567749f, + 0.2380000054836273193f, + 0.4619999825954437256f, + 1.261999964714050293f, + 0.0899999961256980896f, + 0.1900000125169754028f, + 0.4099999964237213135f, + 1.310000061988830566f, + 0.5379999876022338867f, + 0.2380000054836273193f, + 0.9620000123977661133f, + 1.261999964714050293f, + 0.5900000333786010742f, + 0.1900000125169754028f, + 0.9100000262260437012f, + 1.310000061988830566f, + 0.1000000014901161194f, + 0.1000000014901161194f, + 0.1000000014901161194f, + 0.1000000014901161194f, + 0.1000000014901161194f, + 0.1000000014901161194f, + 0.1000000014901161194f, + 0.1000000014901161194f, 0.0f, 0.0f, 0.0f, @@ -4056,64 +4056,24 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_input_shape_as_constant) SERIALIZED_ZOO, "onnx/priorbox_clustered_input_shape_as_constant.prototxt")); auto test_case = test::TestCase(function); - test_case.add_input({5, 5}); - test_case.add_expected_output(Shape{2, 32}, + test_case.add_input({128, 128}); + test_case.add_expected_output(Shape{2, 12}, { - 0.03800000995397567749, - -0.2619999945163726807, - 0.4619999825954437256, - 0.761999964714050293, - 0.0899999961256980896, - -0.310000002384185791, - 0.4099999964237213135, - 0.8100000619888305664, - 0.5379999876022338867, - -0.2619999945163726807, - 0.9620000123977661133, - 0.761999964714050293, - 0.5900000333786010742, - -0.310000002384185791, - 0.9100000262260437012, - 0.8100000619888305664, - 0.03800000995397567749, - 0.2380000054836273193, - 0.4619999825954437256, - 1.261999964714050293, - 0.0899999961256980896, - 0.1900000125169754028, - 0.4099999964237213135, - 1.310000061988830566, - 0.5379999876022338867, - 0.2380000054836273193, - 0.9620000123977661133, - 1.261999964714050293, - 0.5900000333786010742, - 0.1900000125169754028, - 0.9100000262260437012, - 1.310000061988830566, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.1000000014901161194, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, 0.0f, 0.0f, + 0.5060155987739562988f, + 0.5121093988418579102f, 0.0f, 0.0f, + 1.0f, + 1.0f, 0.0f, 0.0f, + 1.0f, + 1.0f, + 0.1f, + 0.1f, + 0.1f, 0.0f, 0.0f, 0.0f, From d53d73297baec3adc719a0960cde8c9770940736 Mon Sep 17 00:00:00 2001 From: bsledz Date: Mon, 8 Feb 2021 12:44:32 +0100 Subject: [PATCH 04/13] Remove commented code --- .../src/op/org.openvinotoolkit/prior_box_clustered.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp index fcf0584b524c9d..6248360eed6972 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp @@ -39,19 +39,9 @@ namespace ngraph ngraph::op::PriorBoxClusteredAttrs attrs{}; attrs.widths = node.get_attribute_value>("width", {1.0}); attrs.heights = node.get_attribute_value>("height", {1.0}); - // attrs.flip = - // node.get_attribute_value("flip", 0); attrs.clip = node.get_attribute_value("clip", 0); attrs.variances = node.get_attribute_value>("variance", {0.1f}); - // attrs.img_size = - // node.get_attribute_value("img_size", 0); - // attrs.img_h = - // node.get_attribute_value("img_h", 0); - // attrs.img_w = - // node.get_attribute_value("img_w", 0); - // attrs.step = - // node.get_attribute_value("step", 0.0f); attrs.step_heights = node.get_attribute_value("step_h", 0.0f); attrs.step_widths = node.get_attribute_value("step_w", 0.0f); attrs.offset = node.get_attribute_value("offset", 0.0f); From c96c73bd7d64a6d959c6b0de60f8181e83cef473 Mon Sep 17 00:00:00 2001 From: bsledz Date: Mon, 8 Feb 2021 12:45:33 +0100 Subject: [PATCH 05/13] Add priorboxclustered to legacy_ops_to_fixup --- ngraph/frontend/onnx_import/src/core/transform.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/core/transform.hpp b/ngraph/frontend/onnx_import/src/core/transform.hpp index 3abbc32aff8cae..704e528770b4f2 100644 --- a/ngraph/frontend/onnx_import/src/core/transform.hpp +++ b/ngraph/frontend/onnx_import/src/core/transform.hpp @@ -53,8 +53,13 @@ namespace ngraph /// \param model_proto Protobuf message with ONNX model to transform. void expand_onnx_functions(ONNX_NAMESPACE::ModelProto& model_proto); - static const std::vector legacy_ops_to_fixup = { - "DetectionOutput", "FakeQuantize", "GroupNorm", "Normalize", "PriorBox", "Swish"}; + static const std::vector legacy_ops_to_fixup = {"DetectionOutput", + "FakeQuantize", + "GroupNorm", + "Normalize", + "PriorBox", + "PriorBoxClustered", + "Swish"}; /// \brief Add support for models with custom operators mistakenly registered in /// "ai.onnx" domain. From f917ca1390d1d7ab2a273d07b97591ef9199243f Mon Sep 17 00:00:00 2001 From: bsledz Date: Mon, 8 Feb 2021 12:48:01 +0100 Subject: [PATCH 06/13] Disable failing tests on cpu --- ngraph/test/runtime/ie/unit_test.manifest | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index fe1b362af2d91e..e83db6a1e96447 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -1608,3 +1608,9 @@ evaluate_mvn_6_inside_sqrt evaluate_mvn_6_across_chanells evaluate_mvn_6_across_batch IE_CPU.onnx_mvn_v6 + +# Unsupported dynamic ops v0::PriorBoxClustered +onnx_priorbox_clustered + +# PriorBoxClustered operation has a form that is not supported. out should be converted to PriorBoxClusteredIE operation. +onnx_priorbox_clustered_input_shape_as_constant \ No newline at end of file From 282cb6eba441e6e4028ef794c79ac68552d84d72 Mon Sep 17 00:00:00 2001 From: bsledz Date: Tue, 9 Feb 2021 07:57:22 +0100 Subject: [PATCH 07/13] Fix implementation of priorboxclustered op --- .../prior_box_clustered.cpp | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp index 6248360eed6972..76a9b9e0adcf61 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp @@ -26,27 +26,55 @@ namespace ngraph { namespace op { + namespace detail + { + namespace + { + std::shared_ptr + make_slice(std::shared_ptr node, int64_t start, int64_t end) + { + return std::make_shared( + node, + default_opset::Constant::create( + element::i64, Shape{1}, std::vector{start}), + default_opset::Constant::create( + element::i64, Shape{1}, std::vector{end}), + std::vector{0}, // begin mask + std::vector{0}); // end mask + } + } + } // detail + namespace set_1 { OutputVector prior_box_clustered(const Node& node) { using PriorBoxClustered = default_opset::PriorBoxClustered; - auto inputs = node.get_ng_inputs(); - auto layer_shape = inputs[0]; - auto img_shape = inputs[1]; + NGRAPH_CHECK(inputs.size() == 2, "Invalid number of inputs"); + + auto output_shape = std::make_shared(inputs[0]); + auto image_shape = std::make_shared(inputs[1]); + auto output_shape_slice = detail::make_slice(output_shape, 2, 4); + auto image_shape_slice = detail::make_slice(image_shape, 2, 4); ngraph::op::PriorBoxClusteredAttrs attrs{}; attrs.widths = node.get_attribute_value>("width", {1.0}); attrs.heights = node.get_attribute_value>("height", {1.0}); - attrs.clip = node.get_attribute_value("clip", 0); + attrs.clip = static_cast(node.get_attribute_value("clip", 0)); attrs.variances = node.get_attribute_value>("variance", {0.1f}); attrs.step_heights = node.get_attribute_value("step_h", 0.0f); attrs.step_widths = node.get_attribute_value("step_w", 0.0f); attrs.offset = node.get_attribute_value("offset", 0.0f); - return {std::make_shared(layer_shape, img_shape, attrs)}; + auto axes = default_opset::Constant::create( + element::i64, Shape{1}, std::vector{0}); + + return {std::make_shared( + std::make_shared( + output_shape_slice, image_shape_slice, attrs), + axes)}; } } // namespace set_1 From 5bb3909b31ffdfba423af6c0bf09e9bea2dc7f4b Mon Sep 17 00:00:00 2001 From: bsledz Date: Tue, 9 Feb 2021 07:58:59 +0100 Subject: [PATCH 08/13] Update unittests --- .../models/onnx/priorbox_clustered.prototxt | 64 ++++++-- ...clustered_input_shape_as_constant.prototxt | 98 ------------ ...rbox_clustered_most_attrs_default.prototxt | 86 +++++++++++ ngraph/test/onnx/onnx_import.in.cpp | 140 +++++------------- ngraph/test/runtime/ie/unit_test.manifest | 6 - 5 files changed, 172 insertions(+), 222 deletions(-) delete mode 100644 ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt create mode 100644 ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt diff --git a/ngraph/test/models/onnx/priorbox_clustered.prototxt b/ngraph/test/models/onnx/priorbox_clustered.prototxt index 4440fa6dfb81f2..68941b51d9e82d 100644 --- a/ngraph/test/models/onnx/priorbox_clustered.prototxt +++ b/ngraph/test/models/onnx/priorbox_clustered.prototxt @@ -3,30 +3,39 @@ producer_name: "nGraph ONNX Importer" graph { node { domain: "org.openvinotoolkit" - input: "input_shape" - input: "image_shape" + input: "A" + input: "B" output: "out" op_type: "PriorBoxClustered" attribute { name: "width" - floats: 2.12 - floats: 1.6 + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 type: FLOATS } attribute { name: "height" - floats: 5.12 - floats: 5.6 + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 type: FLOATS } attribute { name: "step_w" - f: 0.0 + f: 64 type: FLOAT } + attribute { + name: "clip" + i: 1 + type: INT + } attribute { name: "step_h" - f: 0.0 + f: 64 type: FLOAT } attribute { @@ -35,7 +44,8 @@ graph { type: FLOAT } attribute { - name: "variances" + name: "variance" + floats: 0.1 floats: 0.1 floats: 0.2 floats: 0.2 @@ -44,26 +54,44 @@ graph { } name: "compute_graph" input { - name: "input_shape" + name: "A" type { tensor_type { - elem_type: 7 + elem_type: 1 shape { dim { - dim_value: 2 + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 } } } } } input { - name: "image_shape" + name: "B" type { tensor_type { - elem_type: 7 + elem_type: 1 shape { dim { - dim_value: 2 + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 } } } @@ -78,6 +106,12 @@ graph { dim { dim_value: 1 } + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } } } } diff --git a/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt b/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt deleted file mode 100644 index 70264e7ee7ff02..00000000000000 --- a/ngraph/test/models/onnx/priorbox_clustered_input_shape_as_constant.prototxt +++ /dev/null @@ -1,98 +0,0 @@ -ir_version: 3 -producer_name: "nGraph ONNX Importer" -graph { - node { - output: "input_shape" - op_type: "Constant" - attribute { - name: "value" - t { - dims: 2 - data_type: 7 - int64_data: 1 - int64_data: 1 - name: "const_tensor" - } - type: TENSOR - } - } - node { - domain: "org.openvinotoolkit" - input: "input_shape" - input: "image_shape" - output: "out" - op_type: "PriorBoxClustered" - attribute { - name: "width" - floats: 128 - floats: 512 - floats: 4096 - type: FLOATS - } - attribute { - name: "height" - floats: 128 - floats: 512 - floats: 4096 - type: FLOATS - } - attribute { - name: "step_w" - f: 0.77 - type: FLOAT - } - attribute { - name: "step_h" - f: 1.55 - type: FLOAT - } - attribute { - name: "offset" - f: 1 - type: FLOAT - } - attribute { - name: "clip" - i: 1 - type: INT - } - attribute { - name: "variances" - floats: 1.33 - floats: 2.44 - floats: 0.44 - floats: 2.44 - type: FLOATS - } - } - name: "compute_graph" - input { - name: "image_shape" - type { - tensor_type { - elem_type: 7 - shape { - dim { - dim_value: 2 - } - } - } - } - } - output { - name: "out" - type { - tensor_type { - elem_type: 1 - shape { - dim { - dim_value: 1 - } - } - } - } - } -} -opset_import { - version: 1 -} diff --git a/ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt b/ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt new file mode 100644 index 00000000000000..e898f8f3d850e6 --- /dev/null +++ b/ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt @@ -0,0 +1,86 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + domain: "org.openvinotoolkit" + input: "A" + input: "B" + output: "out" + op_type: "PriorBoxClustered" + attribute { + name: "variance" + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + } + name: "compute_graph" + input { + name: "A" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 1 + } + } + } + } + } + input { + name: "B" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 3 + } + dim { + dim_value: 3 + } + } + } + } + } + output { + name: "out" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 8 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index 8667f8dc9c5e2c..95f28c7e91ec6c 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -3977,112 +3977,46 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered) file_util::path_join(SERIALIZED_ZOO, "onnx/priorbox_clustered.prototxt")); auto test_case = test::TestCase(function); - test_case.add_input({2, 2}); - - test_case.add_input({5, 5}); - test_case.add_expected_output(Shape{2, 32}, - { - 0.03800000995397567749f, - -0.2619999945163726807f, - 0.4619999825954437256f, - 0.761999964714050293f, - 0.0899999961256980896f, - -0.310000002384185791f, - 0.4099999964237213135f, - 0.8100000619888305664f, - 0.5379999876022338867f, - -0.2619999945163726807f, - 0.9620000123977661133f, - 0.761999964714050293f, - 0.5900000333786010742f, - -0.310000002384185791f, - 0.9100000262260437012f, - 0.8100000619888305664f, - 0.03800000995397567749f, - 0.2380000054836273193f, - 0.4619999825954437256f, - 1.261999964714050293f, - 0.0899999961256980896f, - 0.1900000125169754028f, - 0.4099999964237213135f, - 1.310000061988830566f, - 0.5379999876022338867f, - 0.2380000054836273193f, - 0.9620000123977661133f, - 1.261999964714050293f, - 0.5900000333786010742f, - 0.1900000125169754028f, - 0.9100000262260437012f, - 1.310000061988830566f, - 0.1000000014901161194f, - 0.1000000014901161194f, - 0.1000000014901161194f, - 0.1000000014901161194f, - 0.1000000014901161194f, - 0.1000000014901161194f, - 0.1000000014901161194f, - 0.1000000014901161194f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - }); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_input_shape_as_constant) + std::vector A{15.0}; + std::vector B{10.0}; + std::vector output = { + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, + }; + test_case.add_input(A); + test_case.add_input(B); + test_case.add_expected_output(Shape{1, 2, 16}, output); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_most_attrs_default) { auto function = onnx_import::import_onnx_model(file_util::path_join( - SERIALIZED_ZOO, "onnx/priorbox_clustered_input_shape_as_constant.prototxt")); + SERIALIZED_ZOO, "onnx/priorbox_clustered_most_attrs_default.prototxt")); auto test_case = test::TestCase(function); - test_case.add_input({128, 128}); - test_case.add_expected_output(Shape{2, 12}, - { - 0.0f, - 0.0f, - 0.5060155987739562988f, - 0.5121093988418579102f, - 0.0f, - 0.0f, - 1.0f, - 1.0f, - 0.0f, - 0.0f, - 1.0f, - 1.0f, - 0.1f, - 0.1f, - 0.1f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - 0.0f, - }); + std::vector A(1 * 2 * 1); + std::iota(std::begin(A), std::end(A), 0.0f); + std::vector B(1 * 3 * 3); + std::iota(std::begin(B), std::end(B), 0.0f); + std::vector output = {-0.1666666716337203979, + -0.1666666716337203979, + 0.1666666716337203979, + 0.1666666716337203979, + -0.1666666716337203979, + 0.3333333432674407959, + 0.1666666716337203979, + 0.6666666865348815918, + 0.1, + 0.1, + 0.2, + 0.2, + 0.1, + 0.1, + 0.2, + 0.2}; + test_case.add_input(A); + test_case.add_input(B); + test_case.add_expected_output(Shape{1, 2, 8}, output); test_case.run(); } diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index e83db6a1e96447..fe1b362af2d91e 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -1608,9 +1608,3 @@ evaluate_mvn_6_inside_sqrt evaluate_mvn_6_across_chanells evaluate_mvn_6_across_batch IE_CPU.onnx_mvn_v6 - -# Unsupported dynamic ops v0::PriorBoxClustered -onnx_priorbox_clustered - -# PriorBoxClustered operation has a form that is not supported. out should be converted to PriorBoxClusteredIE operation. -onnx_priorbox_clustered_input_shape_as_constant \ No newline at end of file From 7a6757df55762b94bbe2f11b1b287184c770c6d5 Mon Sep 17 00:00:00 2001 From: bsledz Date: Tue, 9 Feb 2021 08:53:47 +0100 Subject: [PATCH 09/13] Move custom onnx op priorboxclustered to priorbox context --- .../src/op/org.openvinotoolkit/prior_box.cpp | 30 +++++++ .../src/op/org.openvinotoolkit/prior_box.hpp | 2 + .../prior_box_clustered.cpp | 86 ------------------- .../prior_box_clustered.hpp | 38 -------- .../frontend/onnx_import/src/ops_bridge.cpp | 1 - 5 files changed, 32 insertions(+), 125 deletions(-) delete mode 100644 ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp delete mode 100644 ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp index a27440a5e34d67..96406cf3df1d4d 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp @@ -83,6 +83,36 @@ namespace ngraph axes)}; } + OutputVector prior_box_clustered(const Node& node) + { + using PriorBoxClustered = default_opset::PriorBoxClustered; + auto inputs = node.get_ng_inputs(); + NGRAPH_CHECK(inputs.size() == 2, "Invalid number of inputs"); + + auto output_shape = std::make_shared(inputs[0]); + auto image_shape = std::make_shared(inputs[1]); + auto output_shape_slice = detail::make_slice(output_shape, 2, 4); + auto image_shape_slice = detail::make_slice(image_shape, 2, 4); + + ngraph::op::PriorBoxClusteredAttrs attrs{}; + attrs.widths = node.get_attribute_value>("width", {1.0}); + attrs.heights = node.get_attribute_value>("height", {1.0}); + attrs.clip = static_cast(node.get_attribute_value("clip", 0)); + attrs.variances = + node.get_attribute_value>("variance", {0.1f}); + attrs.step_heights = node.get_attribute_value("step_h", 0.0f); + attrs.step_widths = node.get_attribute_value("step_w", 0.0f); + attrs.offset = node.get_attribute_value("offset", 0.0f); + + auto axes = default_opset::Constant::create( + element::i64, Shape{1}, std::vector{0}); + + return {std::make_shared( + std::make_shared( + output_shape_slice, image_shape_slice, attrs), + axes)}; + } + } // namespace set_1 } // namespace op diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.hpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.hpp index 800b50f2c785cd..2966ec461dea9d 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.hpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.hpp @@ -29,6 +29,8 @@ namespace ngraph { OutputVector prior_box(const Node& node); + OutputVector prior_box_clustered(const Node& node); + } // namespace set_1 } // namespace op diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp deleted file mode 100644 index 76a9b9e0adcf61..00000000000000 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2021 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 "ngraph/op/prior_box_clustered.hpp" -#include "default_opset.hpp" -#include "ngraph/node.hpp" -#include "onnx_import/core/node.hpp" -#include "op/org.openvinotoolkit/prior_box_clustered.hpp" - -namespace ngraph -{ - namespace onnx_import - { - namespace op - { - namespace detail - { - namespace - { - std::shared_ptr - make_slice(std::shared_ptr node, int64_t start, int64_t end) - { - return std::make_shared( - node, - default_opset::Constant::create( - element::i64, Shape{1}, std::vector{start}), - default_opset::Constant::create( - element::i64, Shape{1}, std::vector{end}), - std::vector{0}, // begin mask - std::vector{0}); // end mask - } - } - } // detail - - namespace set_1 - { - OutputVector prior_box_clustered(const Node& node) - { - using PriorBoxClustered = default_opset::PriorBoxClustered; - auto inputs = node.get_ng_inputs(); - NGRAPH_CHECK(inputs.size() == 2, "Invalid number of inputs"); - - auto output_shape = std::make_shared(inputs[0]); - auto image_shape = std::make_shared(inputs[1]); - auto output_shape_slice = detail::make_slice(output_shape, 2, 4); - auto image_shape_slice = detail::make_slice(image_shape, 2, 4); - - ngraph::op::PriorBoxClusteredAttrs attrs{}; - attrs.widths = node.get_attribute_value>("width", {1.0}); - attrs.heights = node.get_attribute_value>("height", {1.0}); - attrs.clip = static_cast(node.get_attribute_value("clip", 0)); - attrs.variances = - node.get_attribute_value>("variance", {0.1f}); - attrs.step_heights = node.get_attribute_value("step_h", 0.0f); - attrs.step_widths = node.get_attribute_value("step_w", 0.0f); - attrs.offset = node.get_attribute_value("offset", 0.0f); - - auto axes = default_opset::Constant::create( - element::i64, Shape{1}, std::vector{0}); - - return {std::make_shared( - std::make_shared( - output_shape_slice, image_shape_slice, attrs), - axes)}; - } - - } // namespace set_1 - - } // namespace op - - } // namespace onnx_import - -} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp deleted file mode 100644 index aa6ac010419f7c..00000000000000 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box_clustered.hpp +++ /dev/null @@ -1,38 +0,0 @@ -//***************************************************************************** -// Copyright 2017-2021 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. -//***************************************************************************** - -#pragma once - -#include "ngraph/node.hpp" -#include "onnx_import/core/node.hpp" - -namespace ngraph -{ - namespace onnx_import - { - namespace op - { - namespace set_1 - { - OutputVector prior_box_clustered(const Node& node); - - } // namespace set_1 - - } // namespace op - - } // namespace onnx_import - -} // namespace ngraph diff --git a/ngraph/frontend/onnx_import/src/ops_bridge.cpp b/ngraph/frontend/onnx_import/src/ops_bridge.cpp index 6ea492ded80de9..019d66466e7f6b 100644 --- a/ngraph/frontend/onnx_import/src/ops_bridge.cpp +++ b/ngraph/frontend/onnx_import/src/ops_bridge.cpp @@ -149,7 +149,6 @@ #include "op/org.openvinotoolkit/group_norm.hpp" #include "op/org.openvinotoolkit/normalize.hpp" #include "op/org.openvinotoolkit/prior_box.hpp" -#include "op/org.openvinotoolkit/prior_box_clustered.hpp" #include "op/org.openvinotoolkit/swish.hpp" namespace ngraph From b98b8b5c46afe45905b4e0b0ec8eb7531b4fefeb Mon Sep 17 00:00:00 2001 From: bsledz Date: Tue, 9 Feb 2021 11:17:59 +0100 Subject: [PATCH 10/13] Move priorboxClustered tests to org_openvino specfic test file --- ngraph/test/onnx/onnx_import.in.cpp | 50 ------------------ .../test/onnx/onnx_import_org_openvino.in.cpp | 52 ++++++++++++++++++- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index 0c3071284b8aaa..ae3aa11ccfe2a0 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -3835,53 +3835,3 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_mvn_v6) 1.2906139, 1.1860244, -0.92945826, 0.0721334, -0.38174, -1.7799333}); test_case.run(); } - -NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered) -{ - auto function = onnx_import::import_onnx_model( - file_util::path_join(SERIALIZED_ZOO, "onnx/priorbox_clustered.prototxt")); - - auto test_case = test::TestCase(function); - std::vector A{15.0}; - std::vector B{10.0}; - std::vector output = { - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, - }; - test_case.add_input(A); - test_case.add_input(B); - test_case.add_expected_output(Shape{1, 2, 16}, output); - test_case.run(); -} - -NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_most_attrs_default) -{ - auto function = onnx_import::import_onnx_model(file_util::path_join( - SERIALIZED_ZOO, "onnx/priorbox_clustered_most_attrs_default.prototxt")); - - auto test_case = test::TestCase(function); - std::vector A(1 * 2 * 1); - std::iota(std::begin(A), std::end(A), 0.0f); - std::vector B(1 * 3 * 3); - std::iota(std::begin(B), std::end(B), 0.0f); - std::vector output = {-0.1666666716337203979, - -0.1666666716337203979, - 0.1666666716337203979, - 0.1666666716337203979, - -0.1666666716337203979, - 0.3333333432674407959, - 0.1666666716337203979, - 0.6666666865348815918, - 0.1, - 0.1, - 0.2, - 0.2, - 0.1, - 0.1, - 0.2, - 0.2}; - test_case.add_input(A); - test_case.add_input(B); - test_case.add_expected_output(Shape{1, 2, 8}, output); - test_case.run(); -} diff --git a/ngraph/test/onnx/onnx_import_org_openvino.in.cpp b/ngraph/test/onnx/onnx_import_org_openvino.in.cpp index dfd2f025bb98f9..a9293427313079 100644 --- a/ngraph/test/onnx/onnx_import_org_openvino.in.cpp +++ b/ngraph/test/onnx/onnx_import_org_openvino.in.cpp @@ -88,6 +88,56 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_prior_box) test_case.run(); } +NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered) +{ + auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/priorbox_clustered.prototxt")); + + auto test_case = test::TestCase(function); + std::vector A{15.0}; + std::vector B{10.0}; + std::vector output = { + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.2, 0.2, + }; + test_case.add_input(A); + test_case.add_input(B); + test_case.add_expected_output(Shape{1, 2, 16}, output); + test_case.run(); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_most_attrs_default) +{ + auto function = onnx_import::import_onnx_model(file_util::path_join( + SERIALIZED_ZOO, "onnx/priorbox_clustered_most_attrs_default.prototxt")); + + auto test_case = test::TestCase(function); + std::vector A(1 * 1 * 2 * 1); + std::iota(std::begin(A), std::end(A), 0.0f); + std::vector B(1 * 1 * 3 * 3); + std::iota(std::begin(B), std::end(B), 0.0f); + std::vector output = {-0.1666666716337203979, + -0.1666666716337203979, + 0.1666666716337203979, + 0.1666666716337203979, + -0.1666666716337203979, + 0.3333333432674407959, + 0.1666666716337203979, + 0.6666666865348815918, + 0.1, + 0.1, + 0.2, + 0.2, + 0.1, + 0.1, + 0.2, + 0.2}; + test_case.add_input(A); + test_case.add_input(B); + test_case.add_expected_output(Shape{1, 2, 8}, output); + test_case.run(); +} + NGRAPH_TEST(${BACKEND_NAME}, onnx_detection_output) { const auto function = onnx_import::import_onnx_model( @@ -490,4 +540,4 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_experimental_detectron_topk_rios) test_case.add_expected_output(Shape{1, 4}, {1, 1, 3, 4}); test_case.run(); -} \ No newline at end of file +} From 79ce7759d203be9c534dffc675e772be1855ca8a Mon Sep 17 00:00:00 2001 From: bsledz Date: Tue, 9 Feb 2021 14:19:43 +0100 Subject: [PATCH 11/13] Remove redundant using clause --- .../onnx_import/src/op/org.openvinotoolkit/prior_box.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp index 96406cf3df1d4d..0a00ff627925f5 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp @@ -85,7 +85,6 @@ namespace ngraph OutputVector prior_box_clustered(const Node& node) { - using PriorBoxClustered = default_opset::PriorBoxClustered; auto inputs = node.get_ng_inputs(); NGRAPH_CHECK(inputs.size() == 2, "Invalid number of inputs"); @@ -108,7 +107,7 @@ namespace ngraph element::i64, Shape{1}, std::vector{0}); return {std::make_shared( - std::make_shared( + std::make_shared( output_shape_slice, image_shape_slice, attrs), axes)}; } From de0ec1a157dd10a82f1f62e1451d55343374537e Mon Sep 17 00:00:00 2001 From: bsledz Date: Wed, 10 Feb 2021 12:57:24 +0100 Subject: [PATCH 12/13] Address requested changes --- .../src/op/org.openvinotoolkit/prior_box.cpp | 18 ++- ...x_clustered_first_input_bad_shape.prototxt | 125 ++++++++++++++++++ ..._clustered_second_input_bad_shape.prototxt | 125 ++++++++++++++++++ .../test/onnx/onnx_import_org_openvino.in.cpp | 40 ++++++ 4 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 ngraph/test/models/onnx/priorbox_clustered_first_input_bad_shape.prototxt create mode 100644 ngraph/test/models/onnx/priorbox_clustered_second_input_bad_shape.prototxt diff --git a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp index 0a00ff627925f5..14a7b48e11d019 100644 --- a/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp +++ b/ngraph/frontend/onnx_import/src/op/org.openvinotoolkit/prior_box.cpp @@ -16,6 +16,7 @@ #include "ngraph/op/prior_box.hpp" #include "default_opset.hpp" +#include "exceptions.hpp" #include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" #include "op/org.openvinotoolkit/prior_box.hpp" @@ -88,14 +89,27 @@ namespace ngraph auto inputs = node.get_ng_inputs(); NGRAPH_CHECK(inputs.size() == 2, "Invalid number of inputs"); + auto output_shape_rank = inputs[0].get_partial_shape().rank().get_length(); + auto image_shape_rank = inputs[1].get_partial_shape().rank().get_length(); + CHECK_VALID_NODE(node, + output_shape_rank == 4, + "Only 4D inputs are supported. First input rank: ", + output_shape_rank, + " (should be 4)"); + CHECK_VALID_NODE(node, + image_shape_rank == 4, + "Only 4D inputs are supported. Second input rank: ", + image_shape_rank, + " (should be 4)"); + auto output_shape = std::make_shared(inputs[0]); auto image_shape = std::make_shared(inputs[1]); auto output_shape_slice = detail::make_slice(output_shape, 2, 4); auto image_shape_slice = detail::make_slice(image_shape, 2, 4); ngraph::op::PriorBoxClusteredAttrs attrs{}; - attrs.widths = node.get_attribute_value>("width", {1.0}); - attrs.heights = node.get_attribute_value>("height", {1.0}); + attrs.widths = node.get_attribute_value>("width"); + attrs.heights = node.get_attribute_value>("height"); attrs.clip = static_cast(node.get_attribute_value("clip", 0)); attrs.variances = node.get_attribute_value>("variance", {0.1f}); diff --git a/ngraph/test/models/onnx/priorbox_clustered_first_input_bad_shape.prototxt b/ngraph/test/models/onnx/priorbox_clustered_first_input_bad_shape.prototxt new file mode 100644 index 00000000000000..48d4076d4e4b7e --- /dev/null +++ b/ngraph/test/models/onnx/priorbox_clustered_first_input_bad_shape.prototxt @@ -0,0 +1,125 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + domain: "org.openvinotoolkit" + input: "A" + input: "B" + output: "out" + op_type: "PriorBoxClustered" + attribute { + name: "width" + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + attribute { + name: "height" + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + attribute { + name: "step_w" + f: 64 + type: FLOAT + } + attribute { + name: "clip" + i: 1 + type: INT + } + attribute { + name: "step_h" + f: 64 + type: FLOAT + } + attribute { + name: "offset" + f: 0.5 + type: FLOAT + } + attribute { + name: "variance" + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + } + name: "compute_graph" + input { + name: "A" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + } + } + } + } + input { + name: "B" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + } + } + } + } + output { + name: "out" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/models/onnx/priorbox_clustered_second_input_bad_shape.prototxt b/ngraph/test/models/onnx/priorbox_clustered_second_input_bad_shape.prototxt new file mode 100644 index 00000000000000..8d53532b3742b0 --- /dev/null +++ b/ngraph/test/models/onnx/priorbox_clustered_second_input_bad_shape.prototxt @@ -0,0 +1,125 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + domain: "org.openvinotoolkit" + input: "A" + input: "B" + output: "out" + op_type: "PriorBoxClustered" + attribute { + name: "width" + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + attribute { + name: "height" + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + attribute { + name: "step_w" + f: 64 + type: FLOAT + } + attribute { + name: "clip" + i: 1 + type: INT + } + attribute { + name: "step_h" + f: 64 + type: FLOAT + } + attribute { + name: "offset" + f: 0.5 + type: FLOAT + } + attribute { + name: "variance" + floats: 0.1 + floats: 0.1 + floats: 0.2 + floats: 0.2 + type: FLOATS + } + } + name: "compute_graph" + input { + name: "A" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + } + } + } + } + input { + name: "B" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + dim { + dim_value: 1 + } + } + } + } + } + output { + name: "out" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 1 + } + dim { + dim_value: 2 + } + dim { + dim_value: 4 + } + } + } + } + } +} +opset_import { + version: 1 +} diff --git a/ngraph/test/onnx/onnx_import_org_openvino.in.cpp b/ngraph/test/onnx/onnx_import_org_openvino.in.cpp index a9293427313079..c4eb1180fea4d3 100644 --- a/ngraph/test/onnx/onnx_import_org_openvino.in.cpp +++ b/ngraph/test/onnx/onnx_import_org_openvino.in.cpp @@ -138,6 +138,46 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_most_attrs_default) test_case.run(); } +NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_first_input_bad_shape) +{ + try + { + auto function = onnx_import::import_onnx_model(file_util::path_join( + SERIALIZED_ZOO, "onnx/priorbox_clustered_first_input_bad_shape.prototxt")); + FAIL() << "Expected exception was not thrown"; + } + catch (const ngraph::ngraph_error& e) + { + EXPECT_HAS_SUBSTRING( + e.what(), + std::string("Only 4D inputs are supported. First input rank: 5 (should be 4)")); + } + catch (...) + { + FAIL() << "Expected OnnxNodeValidationFailure exception was not thrown"; + } +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_priorbox_clustered_second_input_bad_shape) +{ + try + { + auto function = onnx_import::import_onnx_model(file_util::path_join( + SERIALIZED_ZOO, "onnx/priorbox_clustered_second_input_bad_shape.prototxt")); + FAIL() << "Expected exception was not thrown"; + } + catch (const ngraph::ngraph_error& e) + { + EXPECT_HAS_SUBSTRING( + e.what(), + std::string("Only 4D inputs are supported. Second input rank: 5 (should be 4)")); + } + catch (...) + { + FAIL() << "Expected OnnxNodeValidationFailure exception was not thrown"; + } +} + NGRAPH_TEST(${BACKEND_NAME}, onnx_detection_output) { const auto function = onnx_import::import_onnx_model( From b0c8246c5d37a1c326f477e3bd7016b73e9b706c Mon Sep 17 00:00:00 2001 From: bsledz Date: Wed, 10 Feb 2021 14:10:13 +0100 Subject: [PATCH 13/13] Fix one of test models --- .../priorbox_clustered_most_attrs_default.prototxt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt b/ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt index e898f8f3d850e6..ac7c62bdf3663a 100644 --- a/ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt +++ b/ngraph/test/models/onnx/priorbox_clustered_most_attrs_default.prototxt @@ -15,6 +15,16 @@ graph { floats: 0.2 type: FLOATS } + attribute { + name: "width" + floats: 1.0 + type: FLOATS + } + attribute { + name: "height" + floats: 1.0 + type: FLOATS + } } name: "compute_graph" input {