From 3f0a56e46f5d7d99499cb761ee550e060e76026e Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Thu, 6 May 2021 11:12:12 +0200 Subject: [PATCH 01/13] Add Reverse Op to opset --- ngraph/core/include/ngraph/opsets/opset7_tbl.hpp | 1 + ngraph/frontend/onnx_import/src/op/argmax.cpp | 12 ++++++------ .../src/utils/arg_min_max_factory.cpp | 16 +++++++++++++++- .../src/utils/arg_min_max_factory.hpp | 1 + ngraph/python/tests/test_onnx/test_backend.py | 2 +- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp b/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp index b35dba55a1d8bf..d2ca5b73cba9d1 100644 --- a/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp +++ b/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp @@ -90,6 +90,7 @@ NGRAPH_OP(RegionYolo, ngraph::op::v0) NGRAPH_OP(ReorgYolo, ngraph::op::v0) NGRAPH_OP(Reshape, ngraph::op::v1) NGRAPH_OP(Result, ngraph::op::v0) +NGRAPH_OP(Reverse, ngraph::op::v1) NGRAPH_OP(ReverseSequence, ngraph::op::v0) NGRAPH_OP(ROIPooling, ngraph::op::v0) NGRAPH_OP(ScatterNDUpdate, ngraph::op::v3) diff --git a/ngraph/frontend/onnx_import/src/op/argmax.cpp b/ngraph/frontend/onnx_import/src/op/argmax.cpp index e91983528e20b3..d61f2af2ef57e2 100644 --- a/ngraph/frontend/onnx_import/src/op/argmax.cpp +++ b/ngraph/frontend/onnx_import/src/op/argmax.cpp @@ -26,12 +26,12 @@ namespace ngraph { OutputVector argmax(const Node& node) { - const auto select_last_index = - node.get_attribute_value("select_last_index", 0); - CHECK_VALID_NODE(node, - select_last_index == 0, - "Mode 'select_last_index=1' is not supported by current " - "implementation of ArgMax"); + // const auto select_last_index = + // node.get_attribute_value("select_last_index", 0); + // CHECK_VALID_NODE(node, + // select_last_index == 0, + // "Mode 'select_last_index=1' is not supported by current " + // "implementation of ArgMax"); const utils::ArgMinMaxFactory arg_factory(node); return {arg_factory.make_arg_max()}; diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index b0378fae0f497b..da6d4b7130e585 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -15,6 +15,8 @@ namespace ngraph ArgMinMaxFactory::ArgMinMaxFactory(const Node& node) : m_keep_dims{node.get_attribute_value("keepdims", 1)} , m_axis{node.get_attribute_value("axis", 0)} + , m_select_last_index{ + node.get_attribute_value("select_last_index", 0)} { m_input_node = node.get_ng_inputs().at(0); } @@ -34,9 +36,20 @@ namespace ngraph { const auto k_node = default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); - const auto topk = std::make_shared( + auto topk = std::make_shared( m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); + if (m_select_last_index == 1) + { + const auto axis_node = + default_opset::Constant::create(ngraph::element::i64, Shape{1}, {m_axis}); + const auto reverse = std::make_shared( + m_input_node, axis_node, default_opset::Reverse::Mode::INDEX); + + topk = std::make_shared( + reverse, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); + } + if (m_keep_dims == 0) { const auto axis_to_remove = @@ -46,6 +59,7 @@ namespace ngraph return std::make_shared(reshaped_indices, element::i64); } + return std::make_shared(topk->output(1), element::i64); } } // namespace utils diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp index fadd83a083cf7a..b76cd649761158 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.hpp @@ -39,6 +39,7 @@ namespace ngraph const std::int64_t m_keep_dims; Output m_input_node; std::int64_t m_axis; + std::int64_t m_select_last_index; }; } // namespace utils diff --git a/ngraph/python/tests/test_onnx/test_backend.py b/ngraph/python/tests/test_onnx/test_backend.py index ebfd747406ea20..2afa86cb74ff6f 100644 --- a/ngraph/python/tests/test_onnx/test_backend.py +++ b/ngraph/python/tests/test_onnx/test_backend.py @@ -167,7 +167,7 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None "OnnxBackendNodeModelTest.test_min_uint64_cpu"), (xfail_issue_46765, "OnnxBackendNodeModelTest.test_argmax_negative_axis_keepdims_example_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmax_keepdims_example_select_last_index_cpu", + # "OnnxBackendNodeModelTest.test_argmax_keepdims_example_select_last_index_cpu", "OnnxBackendNodeModelTest.test_argmax_no_keepdims_example_select_last_index_cpu", "OnnxBackendNodeModelTest.test_argmin_negative_axis_keepdims_example_select_last_index_cpu", "OnnxBackendNodeModelTest.test_argmin_keepdims_example_select_last_index_cpu", From 5fc3726a8d5ff40cc7e029f1167e9524a508c633 Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Fri, 14 May 2021 14:26:33 +0200 Subject: [PATCH 02/13] Worksave with Reverse path --- .../src/utils/arg_min_max_factory.cpp | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index da6d4b7130e585..35dc88d7c6dbb6 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -34,33 +34,37 @@ namespace ngraph std::shared_ptr ArgMinMaxFactory::make_topk_subgraph(default_opset::TopK::Mode mode) const { - const auto k_node = - default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); - auto topk = std::make_shared( - m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); - if (m_select_last_index == 1) { const auto axis_node = default_opset::Constant::create(ngraph::element::i64, Shape{1}, {m_axis}); + const auto reverse = std::make_shared( m_input_node, axis_node, default_opset::Reverse::Mode::INDEX); - topk = std::make_shared( - reverse, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); - } + - if (m_keep_dims == 0) + } + else { - const auto axis_to_remove = - default_opset::Constant::create(element::u64, Shape{}, {topk->get_axis()}); - const auto reshaped_indices = - std::make_shared(topk->output(1), axis_to_remove); + const auto k_node = + default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); + auto topk = std::make_shared( + m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); - return std::make_shared(reshaped_indices, element::i64); - } + if (m_keep_dims == 0) + { + const auto axis_to_remove = default_opset::Constant::create( + element::u64, Shape{}, {topk->get_axis()}); + const auto reshaped_indices = std::make_shared( + topk->output(1), axis_to_remove); + + return std::make_shared(reshaped_indices, + element::i64); + } - return std::make_shared(topk->output(1), element::i64); + return std::make_shared(topk->output(1), element::i64); + } } } // namespace utils } // namespace onnx_import From 482addd0a377ae64a384ff520218616363140181 Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Mon, 17 May 2021 03:28:07 +0200 Subject: [PATCH 03/13] Add last_index support --- ngraph/frontend/onnx_import/src/op/argmax.cpp | 7 ------ ngraph/frontend/onnx_import/src/op/argmin.cpp | 7 ------ .../src/utils/arg_min_max_factory.cpp | 23 +++++++++++++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/op/argmax.cpp b/ngraph/frontend/onnx_import/src/op/argmax.cpp index d61f2af2ef57e2..1356626c5c3562 100644 --- a/ngraph/frontend/onnx_import/src/op/argmax.cpp +++ b/ngraph/frontend/onnx_import/src/op/argmax.cpp @@ -26,13 +26,6 @@ namespace ngraph { OutputVector argmax(const Node& node) { - // const auto select_last_index = - // node.get_attribute_value("select_last_index", 0); - // CHECK_VALID_NODE(node, - // select_last_index == 0, - // "Mode 'select_last_index=1' is not supported by current " - // "implementation of ArgMax"); - const utils::ArgMinMaxFactory arg_factory(node); return {arg_factory.make_arg_max()}; } diff --git a/ngraph/frontend/onnx_import/src/op/argmin.cpp b/ngraph/frontend/onnx_import/src/op/argmin.cpp index 983a8dae8ca099..53478f48a59ccf 100644 --- a/ngraph/frontend/onnx_import/src/op/argmin.cpp +++ b/ngraph/frontend/onnx_import/src/op/argmin.cpp @@ -26,13 +26,6 @@ namespace ngraph { OutputVector argmin(const Node& node) { - const auto select_last_index = - node.get_attribute_value("select_last_index", 0); - CHECK_VALID_NODE(node, - select_last_index == 0, - "Mode 'select_last_index=1' is not supported by current " - "implementation of ArgMin"); - const utils::ArgMinMaxFactory arg_factory(node); return {arg_factory.make_arg_min()}; } diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index 35dc88d7c6dbb6..9fbbebeb966750 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -34,21 +34,36 @@ namespace ngraph std::shared_ptr ArgMinMaxFactory::make_topk_subgraph(default_opset::TopK::Mode mode) const { + const auto k_node = + default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); + if (m_select_last_index == 1) { const auto axis_node = default_opset::Constant::create(ngraph::element::i64, Shape{1}, {m_axis}); - const auto reverse = std::make_shared( + auto reverse = std::make_shared( m_input_node, axis_node, default_opset::Reverse::Mode::INDEX); - + auto topk = std::make_shared( + reverse, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); + + auto data_shape = std::make_shared(m_input_node); + + auto dims_on_axis = std::make_shared( + data_shape, + axis_node, + default_opset::Constant::create(ngraph::element::i64, Shape{}, {0})); + auto result = std::make_shared( + dims_on_axis, + std::make_shared(topk->output(1), element::i64)); + return std::make_shared( + result, + default_opset::Constant::create(ngraph::element::i64, Shape{1}, {1})); } else { - const auto k_node = - default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); auto topk = std::make_shared( m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); From e225b8e81073a6c7df1936fa8dbd3c8de5063841 Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Mon, 17 May 2021 16:19:49 +0200 Subject: [PATCH 04/13] refactor argminmax factory --- .../src/utils/arg_min_max_factory.cpp | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index 9fbbebeb966750..6f68f96df7e18f 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -37,11 +37,11 @@ namespace ngraph const auto k_node = default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); + // Reverse input for top-k if (m_select_last_index == 1) { const auto axis_node = default_opset::Constant::create(ngraph::element::i64, Shape{1}, {m_axis}); - auto reverse = std::make_shared( m_input_node, axis_node, default_opset::Reverse::Mode::INDEX); @@ -49,37 +49,44 @@ namespace ngraph reverse, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); auto data_shape = std::make_shared(m_input_node); - auto dims_on_axis = std::make_shared( data_shape, axis_node, default_opset::Constant::create(ngraph::element::i64, Shape{}, {0})); - auto result = std::make_shared( + auto res_index = std::make_shared( dims_on_axis, std::make_shared(topk->output(1), element::i64)); - return std::make_shared( - result, + auto result = std::make_shared( + res_index, default_opset::Constant::create(ngraph::element::i64, Shape{1}, {1})); - } - else - { - auto topk = std::make_shared( - m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); if (m_keep_dims == 0) { const auto axis_to_remove = default_opset::Constant::create( element::u64, Shape{}, {topk->get_axis()}); - const auto reshaped_indices = std::make_shared( - topk->output(1), axis_to_remove); - return std::make_shared(reshaped_indices, - element::i64); + return std::make_shared(result, axis_to_remove); } - return std::make_shared(topk->output(1), element::i64); + return result; } + + auto topk = std::make_shared( + m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); + + auto result = + std::make_shared(topk->output(1), element::i64); + + if (m_keep_dims == 0) + { + const auto axis_to_remove = + default_opset::Constant::create(element::u64, Shape{}, {topk->get_axis()}); + + return std::make_shared(result, axis_to_remove); + } + + return result; } } // namespace utils } // namespace onnx_import From be6d2c8b2448e679140aa624b63342ad39754d5d Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Mon, 17 May 2021 16:54:04 +0200 Subject: [PATCH 05/13] Remove old xfail, add new one --- ngraph/python/tests/__init__.py | 2 +- ngraph/python/tests/test_onnx/test_backend.py | 20 ++++--------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/ngraph/python/tests/__init__.py b/ngraph/python/tests/__init__.py index 5b487cacbc917c..3a8a11fd9ddd66 100644 --- a/ngraph/python/tests/__init__.py +++ b/ngraph/python/tests/__init__.py @@ -113,12 +113,12 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True): xfail_issue_44976 = xfail_test(reason="E RuntimeError: Quantize layer with name:" "FakeQuantize_xxx has non const input on 1 port") xfail_issue_46762 = xfail_test(reason="Incorrect result of Minimum op if uint data type is used") -xfail_issue_46765 = xfail_test(reason="select_last_index attribute is not supported by ArgMin and ArgMax") xfail_issue_47323 = xfail_test(reason="RuntimeError: The plugin does not support FP64") xfail_issue_47337 = xfail_test(reason="RuntimeError: Unsupported dynamic ops: v1::OneHot") xfail_issue_33593 = xfail_test(reason="Current implementation of MaxPool doesn't support indices output") xfail_issue_51993 = xfail_test(reason="PRelu supports only 1D tensor for 'slope' input broadcasted" "by channel") +xfail_issue_55760 = xfail_test(reason="RuntimeError: Reversed axis have axes above the source space shape") # Model MSFT issues: xfail_issue_37957 = xfail_test(reason="RuntimeError: nGraph does not support the following ONNX operations:" diff --git a/ngraph/python/tests/test_onnx/test_backend.py b/ngraph/python/tests/test_onnx/test_backend.py index 2afa86cb74ff6f..d411919e97785e 100644 --- a/ngraph/python/tests/test_onnx/test_backend.py +++ b/ngraph/python/tests/test_onnx/test_backend.py @@ -50,7 +50,6 @@ xfail_issue_45180, xfail_issue_45344, xfail_issue_46762, - xfail_issue_46765, xfail_issue_47323, xfail_issue_47337, xfail_issue_48052, @@ -60,7 +59,8 @@ xfail_issue_49753, xfail_issue_49754, xfail_issue_52463, - xfail_issue_51993) + xfail_issue_51993, + xfail_issue_55760) def expect_fail(test_case_path, xfail): # type: (str) -> None @@ -165,23 +165,11 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None "OnnxBackendNodeModelTest.test_min_uint16_cpu", "OnnxBackendNodeModelTest.test_min_uint32_cpu", "OnnxBackendNodeModelTest.test_min_uint64_cpu"), - (xfail_issue_46765, + (xfail_issue_55760, "OnnxBackendNodeModelTest.test_argmax_negative_axis_keepdims_example_select_last_index_cpu", - # "OnnxBackendNodeModelTest.test_argmax_keepdims_example_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmax_no_keepdims_example_select_last_index_cpu", "OnnxBackendNodeModelTest.test_argmin_negative_axis_keepdims_example_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmin_keepdims_example_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmin_no_keepdims_example_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmax_default_axis_example_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmax_default_axis_random_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmax_keepdims_random_select_last_index_cpu", "OnnxBackendNodeModelTest.test_argmax_negative_axis_keepdims_random_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmax_no_keepdims_random_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmin_default_axis_example_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmin_default_axis_random_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmin_keepdims_random_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmin_negative_axis_keepdims_random_select_last_index_cpu", - "OnnxBackendNodeModelTest.test_argmin_no_keepdims_random_select_last_index_cpu"), + "OnnxBackendNodeModelTest.test_argmin_negative_axis_keepdims_random_select_last_index_cpu"), (xfail_issue_38091, "OnnxBackendNodeModelTest.test_gather_negative_indices_cpu"), (xfail_issue_52463, From 8d67e6f1a0944cbf09d6b6fce7305446c4eb9832 Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Mon, 17 May 2021 22:27:15 +0200 Subject: [PATCH 06/13] Fix proto file for argmax --- ngraph/test/models/onnx/argmax_select_last_index.prototxt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ngraph/test/models/onnx/argmax_select_last_index.prototxt b/ngraph/test/models/onnx/argmax_select_last_index.prototxt index ba73f63c1952ba..d47a89d14a0a0e 100644 --- a/ngraph/test/models/onnx/argmax_select_last_index.prototxt +++ b/ngraph/test/models/onnx/argmax_select_last_index.prototxt @@ -50,6 +50,9 @@ graph { dim { dim_value: 3 } + dim { + dim_value: 1 + } } } } From 141eae1406047b30a347fb65572fa3f6bf388c0e Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Mon, 17 May 2021 22:27:44 +0200 Subject: [PATCH 07/13] Rewrite test for select_last_index --- ngraph/test/onnx/onnx_import.in.cpp | 49 +++++++++-------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/ngraph/test/onnx/onnx_import.in.cpp b/ngraph/test/onnx/onnx_import.in.cpp index bf9551a5cfbf73..6c0438afac145e 100644 --- a/ngraph/test/onnx/onnx_import.in.cpp +++ b/ngraph/test/onnx/onnx_import.in.cpp @@ -2503,45 +2503,24 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_float) NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmax_select_last_index) { - try - { - auto function = onnx_import::import_onnx_model( - file_util::path_join(SERIALIZED_ZOO, "onnx/argmax_select_last_index.prototxt")); - FAIL() << "Expected exception was not thrown"; - } - catch (const ngraph::ngraph_error& e) - { - EXPECT_HAS_SUBSTRING( - e.what(), - std::string( - "Mode 'select_last_index=1' is not supported by current implementation of ArgMax")); - } - catch (...) - { - FAIL() << "Expected OnnxNodeValidationFailure exception was not thrown"; - } + auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/argmax_select_last_index.prototxt")); + + auto test_case = test::TestCase(function); + test_case.add_input(Shape{4, 3}, {1, 1, 1, 0.5, 3, 4, 0.5, 1, 1.1, 0, 3, 0}); + test_case.add_expected_output(Shape{1, 3}, {0, 3, 1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, onnx_model_argmin_select_last_index) { - try - { - auto function = onnx_import::import_onnx_model( - file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_select_last_index.prototxt")); - FAIL() << "Expected exception was not thrown"; - } - catch (const ngraph::ngraph_error& e) - { - EXPECT_HAS_SUBSTRING( - e.what(), - std::string( - "Mode 'select_last_index=1' is not supported by current implementation of ArgMin")); - std::string what{e.what()}; - } - catch (...) - { - FAIL() << "Expected OnnxNodeValidationFailure exception was not thrown"; - } + auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/argmin_select_last_index.prototxt")); + + auto test_case = test::TestCase(function); + test_case.add_input(Shape{4, 3}, {1, 1, 1, 2, 3, 4, 2, 1, 1.1, 3, 3, 8}); + test_case.add_expected_output(Shape{4}, {2, 0, 1, 1}); + test_case.run(); } NGRAPH_TEST(${BACKEND_NAME}, onnx_model_top_k) From 5bdf1ecb1914aca1cc6f27ab95d10ea73252c3e8 Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Mon, 17 May 2021 22:28:09 +0200 Subject: [PATCH 08/13] Add CPU tests to Manifest --- ngraph/test/runtime/ie/unit_test.manifest | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 5273db1149dcc3..9d534120cae9a5 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -132,6 +132,14 @@ arg_max_dyn_shape onnx_model_argmax_float onnx_model_argmin_float +# Result mismatch +# Failure +# Value of: res +# Actual: false +# Expected: true +onnx_model_argmax_select_last_index +onnx_model_argmin_select_last_index + # Constant has zero dimension that is not allowable onnx_dyn_shapes_transpose From 9b5ca878ccad2c2da1b12eea1b755dbab5829f4a Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Mon, 17 May 2021 22:43:30 +0200 Subject: [PATCH 09/13] Update manifest --- ngraph/test/runtime/ie/unit_test.manifest | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 9d534120cae9a5..e234050ea2cf51 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -131,12 +131,6 @@ arg_max_dyn_shape # Result mismatch onnx_model_argmax_float onnx_model_argmin_float - -# Result mismatch -# Failure -# Value of: res -# Actual: false -# Expected: true onnx_model_argmax_select_last_index onnx_model_argmin_select_last_index From 456d507bb126272e4d710c5efb03233bac0487df Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Wed, 19 May 2021 11:50:50 +0200 Subject: [PATCH 10/13] Remove Reverse from opset7 --- ngraph/core/include/ngraph/opsets/opset7_tbl.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp b/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp index d2ca5b73cba9d1..b35dba55a1d8bf 100644 --- a/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp +++ b/ngraph/core/include/ngraph/opsets/opset7_tbl.hpp @@ -90,7 +90,6 @@ NGRAPH_OP(RegionYolo, ngraph::op::v0) NGRAPH_OP(ReorgYolo, ngraph::op::v0) NGRAPH_OP(Reshape, ngraph::op::v1) NGRAPH_OP(Result, ngraph::op::v0) -NGRAPH_OP(Reverse, ngraph::op::v1) NGRAPH_OP(ReverseSequence, ngraph::op::v0) NGRAPH_OP(ROIPooling, ngraph::op::v0) NGRAPH_OP(ScatterNDUpdate, ngraph::op::v3) From 755160aa0e9cea5209c882dffb91aa1de91b51dd Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Wed, 19 May 2021 11:51:24 +0200 Subject: [PATCH 11/13] Refactor arg_min_max factory --- .../src/utils/arg_min_max_factory.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index 6f68f96df7e18f..fb5595f56884f0 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -4,6 +4,7 @@ #include "utils/arg_min_max_factory.hpp" #include "default_opset.hpp" +#include "ngraph/opsets/opset1.hpp" #include "ngraph/validation_util.hpp" namespace ngraph @@ -14,11 +15,11 @@ namespace ngraph { ArgMinMaxFactory::ArgMinMaxFactory(const Node& node) : m_keep_dims{node.get_attribute_value("keepdims", 1)} + , m_input_node{node.get_ng_inputs().at(0)} , m_axis{node.get_attribute_value("axis", 0)} , m_select_last_index{ node.get_attribute_value("select_last_index", 0)} { - m_input_node = node.get_ng_inputs().at(0); } std::shared_ptr ArgMinMaxFactory::make_arg_max() const @@ -42,22 +43,22 @@ namespace ngraph { const auto axis_node = default_opset::Constant::create(ngraph::element::i64, Shape{1}, {m_axis}); - auto reverse = std::make_shared( - m_input_node, axis_node, default_opset::Reverse::Mode::INDEX); + const auto reverse = std::make_shared( + m_input_node, axis_node, opset1::Reverse::Mode::INDEX); - auto topk = std::make_shared( + const auto topk = std::make_shared( reverse, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); - auto data_shape = std::make_shared(m_input_node); - auto dims_on_axis = std::make_shared( + const auto data_shape = std::make_shared(m_input_node); + const auto dims_on_axis = std::make_shared( data_shape, axis_node, default_opset::Constant::create(ngraph::element::i64, Shape{}, {0})); - auto res_index = std::make_shared( + const auto res_index = std::make_shared( dims_on_axis, std::make_shared(topk->output(1), element::i64)); - auto result = std::make_shared( + const auto result = std::make_shared( res_index, default_opset::Constant::create(ngraph::element::i64, Shape{1}, {1})); @@ -72,10 +73,10 @@ namespace ngraph return result; } - auto topk = std::make_shared( + const auto topk = std::make_shared( m_input_node, k_node, m_axis, mode, default_opset::TopK::SortType::NONE); - auto result = + const auto result = std::make_shared(topk->output(1), element::i64); if (m_keep_dims == 0) From 37261cde179294ddedc282673ae2b391d805b2b0 Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Wed, 19 May 2021 12:38:01 +0200 Subject: [PATCH 12/13] Added example comment in arg_min_max --- .../src/utils/arg_min_max_factory.cpp | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index fb5595f56884f0..cc4f0548ade806 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -38,9 +38,32 @@ namespace ngraph const auto k_node = default_opset::Constant::create(ngraph::element::i64, Shape{}, {1}); - // Reverse input for top-k if (m_select_last_index == 1) { + // Example (ArgMin): + // The goal is to get the index of the last occurence of + // minimum value present in given input tensor. + // + // Input: [1, 2, 1, 3, 4, 4] + // Expected output: [2] + // + // Top-K is always returning the "most-left" result. The trick is to + // reverse input to find the "most-right" occurence which is equal to + // the last occurence in the original input. + // reverse = [4, 4, 3, 1, 2, 1] + // + // Run TopK on reversed tensor, in the example output with index values + // is equal to: + // topk->output(1) = 3 + // + // Using ShapeOf and Gather on input obtain length of the input tensor + // along axis, in the example this is equal to: + // dims_on_axis = 6 + // + // Now using two Substract ops calculate resulting index: + // res_index = dims_on_axis - topk->output(1) = 6 - 3 = 3 + // result = res_index - 1 = 3 - 1 = 2 + const auto axis_node = default_opset::Constant::create(ngraph::element::i64, Shape{1}, {m_axis}); const auto reverse = std::make_shared( From f794c43ca0dde0690097a8330804e70d596bbbc4 Mon Sep 17 00:00:00 2001 From: jiwaszki Date: Wed, 19 May 2021 13:22:29 +0200 Subject: [PATCH 13/13] Codestyle changes --- .../onnx_import/src/utils/arg_min_max_factory.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp index cc4f0548ade806..65bba632482156 100644 --- a/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp +++ b/ngraph/frontend/onnx_import/src/utils/arg_min_max_factory.cpp @@ -41,14 +41,14 @@ namespace ngraph if (m_select_last_index == 1) { // Example (ArgMin): - // The goal is to get the index of the last occurence of + // The goal is to get the index of the last occurence of the // minimum value present in given input tensor. // // Input: [1, 2, 1, 3, 4, 4] // Expected output: [2] // - // Top-K is always returning the "most-left" result. The trick is to - // reverse input to find the "most-right" occurence which is equal to + // Top-K is always returning the "most-left" result. The trick is to + // reverse input to find the "most-right" occurence which is equal to // the last occurence in the original input. // reverse = [4, 4, 3, 1, 2, 1] // @@ -63,7 +63,7 @@ namespace ngraph // Now using two Substract ops calculate resulting index: // res_index = dims_on_axis - topk->output(1) = 6 - 3 = 3 // result = res_index - 1 = 3 - 1 = 2 - + const auto axis_node = default_opset::Constant::create(ngraph::element::i64, Shape{1}, {m_axis}); const auto reverse = std::make_shared(