diff --git a/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp b/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp index c8775bb5bea..8fcf8aeb598 100644 --- a/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp +++ b/inference-engine/src/legacy_api/src/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.cpp @@ -12,7 +12,6 @@ #include "legacy/transformations/convert_opset1_to_legacy/convert_matmul_to_fc_or_gemm.hpp" #include "legacy/transformations/convert_opset1_to_legacy/convert_mul_add_to_scaleshift_or_power.hpp" #include "legacy/transformations/convert_opset1_to_legacy/convert_mul_or_add_finally.hpp" -#include "legacy/transformations/convert_opset1_to_legacy/convert_nms_to_nms_ie.hpp" #include "legacy/transformations/convert_opset1_to_legacy/convert_nms_5_to_legacy.hpp" #include "legacy/transformations/convert_opset1_to_legacy/convert_normalizel2_to_normalize_ie.hpp" #include "legacy/transformations/convert_opset1_to_legacy/convert_one_hot_to_one_hot_ie.hpp" @@ -45,6 +44,7 @@ #include #include +#include #include #include @@ -129,7 +129,10 @@ bool ngraph::pass::ConvertOpSet1ToLegacy::run_on_function(std::shared_ptradd_matcher()->detect_output_type(f); anchor->add_matcher(); anchor->add_matcher(); - anchor->add_matcher(); + anchor->add_matcher(); + anchor->add_matcher(); + anchor->add_matcher(); + anchor->add_matcher(); anchor->add_matcher(); anchor->add_matcher(); anchor->add_matcher(); diff --git a/inference-engine/src/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp b/inference-engine/src/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp index f0296717526..55d98031a3b 100644 --- a/inference-engine/src/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp +++ b/inference-engine/src/transformations/include/transformations/op_conversions/convert_previous_nms_to_nms_5.hpp @@ -16,7 +16,6 @@ namespace pass { class TRANSFORMATIONS_API ConvertNMS1ToNMS5; class TRANSFORMATIONS_API ConvertNMS3ToNMS5; class TRANSFORMATIONS_API ConvertNMS4ToNMS5; -class TRANSFORMATIONS_API ConvertPreviousNMSToNMS5; } // namespace pass } // namespace ngraph @@ -39,12 +38,3 @@ public: ConvertNMS4ToNMS5(); }; -class ngraph::pass::ConvertPreviousNMSToNMS5: public ngraph::pass::GraphRewrite { -public: - NGRAPH_RTTI_DECLARATION; - ConvertPreviousNMSToNMS5() { - add_matcher(); - add_matcher(); - add_matcher(); - } -}; diff --git a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp index 50b3b456bf1..5d637d3a89f 100644 --- a/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp +++ b/inference-engine/src/transformations/src/transformations/common_optimizations/common_optimizations.cpp @@ -113,8 +113,6 @@ bool ngraph::pass::CommonOptimizations::run_on_function(std::shared_ptr(); manager.register_pass(); - manager.register_pass(); - auto fq_fusions = manager.register_pass(); fq_fusions->add_matcher(); fq_fusions->add_matcher(); diff --git a/inference-engine/src/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp b/inference-engine/src/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp index 3328f02058d..974ec8403d2 100644 --- a/inference-engine/src/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp +++ b/inference-engine/src/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp @@ -125,7 +125,7 @@ struct NMSAttributes { return attrs; } - bool callback_func(pattern::Matcher &m) { + bool callback_func(pattern::Matcher &m, pass::MatcherPass * impl) { auto root = m.get_match_root(); auto attrs = get_nms_attrs(root); @@ -141,20 +141,7 @@ struct NMSAttributes { const auto& arg3 = num_of_args > 3 ? new_args.at(3) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); const auto& arg4 = num_of_args > 4 ? new_args.at(4) : ngraph::opset5::Constant::create(element::f32, Shape{}, {.0f}); - // list of new nGraph operations - std::list> new_ops_list; - - if (num_of_args <= 4) { - new_ops_list.push_front(arg4.get_node_shared_ptr()); - } - if (num_of_args <= 3) { - new_ops_list.push_front(arg3.get_node_shared_ptr()); - } - if (num_of_args <= 2) { - new_ops_list.push_front(arg2.get_node_shared_ptr()); - } - - const auto nms_5 = std::make_shared( + const auto nms_5 = impl->register_new_node( new_args.at(0), new_args.at(1), arg2, @@ -164,25 +151,20 @@ struct NMSAttributes { attrs.sort_result_descending, attrs.output_type); - new_ops_list.push_back(nms_5); - - // vector of new nGraph operations - NodeVector new_ops(new_ops_list.begin(), new_ops_list.end()); - nms_5->set_friendly_name(root->get_friendly_name()); - ngraph::copy_runtime_info(root, new_ops); + ngraph::copy_runtime_info(root, nms_5); root->output(0).replace(nms_5->output(0)); return true; } } // namespace -NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertPreviousNMSToNMS5, "ConvertPreviousNMSToNMS5", 0); - NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertNMS4ToNMS5, "ConvertNMS4ToNMS5", 0); ngraph::pass::ConvertNMS4ToNMS5::ConvertNMS4ToNMS5() { auto nms = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = callback_func; + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { + return callback_func(m, this); + }; auto m = std::make_shared(nms, "ConvertNMS4ToNMS5"); this->register_matcher(m, callback); @@ -192,7 +174,9 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertNMS3ToNMS5, "ConvertNMS3ToNMS5", 0); ngraph::pass::ConvertNMS3ToNMS5::ConvertNMS3ToNMS5() { auto nms = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = callback_func; + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { + return callback_func(m, this); + }; auto m = std::make_shared(nms, "ConvertNMS3ToNMS5"); this->register_matcher(m, callback); @@ -202,7 +186,9 @@ NGRAPH_RTTI_DEFINITION(ngraph::pass::ConvertNMS1ToNMS5, "ConvertNMS1ToNMS5", 0); ngraph::pass::ConvertNMS1ToNMS5::ConvertNMS1ToNMS5() { auto nms = ngraph::pattern::wrap_type(); - ngraph::matcher_pass_callback callback = callback_func; + ngraph::matcher_pass_callback callback = [this](pattern::Matcher& m) { + return callback_func(m, this); + }; auto m = std::make_shared(nms, "ConvertNMS1ToNMS5"); this->register_matcher(m, callback); diff --git a/inference-engine/tests/functional/inference_engine/ngraph_reader/non_max_suppression_tests.cpp b/inference-engine/tests/functional/inference_engine/ngraph_reader/non_max_suppression_tests.cpp index 1380bb2196c..884e7a4e635 100644 --- a/inference-engine/tests/functional/inference_engine/ngraph_reader/non_max_suppression_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/ngraph_reader/non_max_suppression_tests.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -366,149 +366,3 @@ TEST_F(NGraphReaderTests, ReadNonMaxSuppression5) { fp32w[4] = 0.0; }); } - -TEST_F(NGraphReaderTests, ReadNonMaxSuppression4) { - std::string model = R"V0G0N( - - - - - - - 1 - 15130 - 4 - - - - - - - - 1 - 80 - 15130 - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - 15130 - 4 - - - 1 - 80 - 15130 - - - - - - - - 16000 - 3 - - - - - - - 16000 - 3 - - - 16000 - 3 - - - - - 16000 - 3 - - - - - - - 16000 - 3 - - - - - - - - - - - - - - - -)V0G0N"; - - constexpr size_t weightsSize = 16; - - Blob::Ptr weights; - - weights = make_shared_blob(TensorDesc(Precision::U8, {weightsSize}, Layout::C)); - weights->allocate(); - CommonTestUtils::fill_data(weights->buffer().as(), weights->size() / sizeof(float)); - - auto * i64w = weights->buffer().as(); - i64w[0] = 200; - - auto * fp32w = weights->buffer().as(); - fp32w[2] = 0.5; - fp32w[3] = 0.05; - - Core ie; - - auto ngraphImpl = ie.ReadNetwork(model, weights); - auto graph = ngraph::clone_function(*ngraphImpl.getFunction()); - - ::ngraph::pass::Manager manager; - manager.register_pass<::ngraph::pass::InitNodeInfo>(); - manager.register_pass<::ngraph::pass::CommonOptimizations>(); - manager.run_passes(graph); - - auto boxes = std::make_shared(element::f32, Shape{1, 15130, 4}); - auto scores = std::make_shared(element::f32, Shape{1, 80, 15130}); - auto max_output_boxes_per_class = opset5::Constant::create(element::i64, Shape{}, {200}); - auto iou_threshold = opset5::Constant::create(element::f32, Shape{}, {0.5}); - auto score_threshold = opset5::Constant::create(element::f32, Shape{}, {0.05}); - auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, iou_threshold, score_threshold, - opset5::NonMaxSuppression::BoxEncodingType::CORNER, true, ngraph::element::i32); - - auto mul = std::make_shared(nms, nms); - auto graph_ref = std::make_shared(NodeVector{mul}, ParameterVector{boxes, scores}); - - auto res = compare_functions(graph, graph_ref); - ASSERT_TRUE(res.first) << res.second; -} diff --git a/inference-engine/tests/functional/inference_engine/transformations/convert_nms_to_nms_ie_test.cpp b/inference-engine/tests/functional/inference_engine/transformations/convert_nms_to_nms_ie_test.cpp index 07529e1cf4b..64a8ca7d6ad 100644 --- a/inference-engine/tests/functional/inference_engine/transformations/convert_nms_to_nms_ie_test.cpp +++ b/inference-engine/tests/functional/inference_engine/transformations/convert_nms_to_nms_ie_test.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "common_test_utils/ngraph_test_utils.hpp" @@ -141,3 +142,121 @@ TEST(TransformationTests, ConvertNMSToNMSIEDynamic2) { auto res = compare_functions(f, f_ref); ASSERT_TRUE(res.first) << res.second; } + +TEST(TransformationTests, ConvertNMST1oNMSIE) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); + auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{}, {10}); + auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); + auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); + auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, + iou_threshold, score_threshold, op::v1::NonMaxSuppression::BoxEncodingType::CORNER, true); + + f = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); + + const auto & orig_shape = f->get_output_partial_shape(0); + ngraph::pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + ASSERT_TRUE(f->get_output_partial_shape(0).is_static()) << "Shape " << f->get_output_partial_shape(0) << " should be static"; + } + + { + auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); + auto max_output_boxes_per_class = opset1::Constant::create(element::i64, Shape{1}, {10}); + auto iou_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.75}); + auto score_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.7}); + auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, + iou_threshold, score_threshold, 0, true, element::i32); + auto convert = std::make_shared(nms->output(0), element::i64); + + f_ref = std::make_shared(NodeVector{convert}, ParameterVector{boxes, scores}); + ASSERT_TRUE(f_ref->get_output_partial_shape(0).is_static()) << "Shape " << f_ref->get_output_partial_shape(0) << " should be static"; + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, ConvertNMST3oNMSIE) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); + auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{}, {10}); + auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); + auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); + auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, + iou_threshold, score_threshold, opset3::NonMaxSuppression::BoxEncodingType::CORNER, true, element::i32); + + f = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); + + const auto & orig_shape = f->get_output_partial_shape(0); + ngraph::pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + ASSERT_TRUE(f->get_output_partial_shape(0).is_static()) << "Shape " << f->get_output_partial_shape(0) << " should be static"; + } + + { + auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); + auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{1}, {10}); + auto iou_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.75}); + auto score_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.7}); + auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, + iou_threshold, score_threshold, 0, true, element::i32); + + f_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); + ASSERT_TRUE(f_ref->get_output_partial_shape(0).is_static()) << "Shape " << f_ref->get_output_partial_shape(0) << " should be static"; + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} + +TEST(TransformationTests, ConvertNMST4oNMSIE) { + std::shared_ptr f(nullptr), f_ref(nullptr); + { + auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); + auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{}, {10}); + auto iou_threshold = opset1::Constant::create(element::f32, Shape{}, {0.75}); + auto score_threshold = opset1::Constant::create(element::f32, Shape{}, {0.7}); + auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, + iou_threshold, score_threshold, opset4::NonMaxSuppression::BoxEncodingType::CORNER, true, element::i32); + + f = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); + + const auto & orig_shape = f->get_output_partial_shape(0); + ngraph::pass::Manager manager; + manager.register_pass(); + manager.register_pass(); + manager.run_passes(f); + ASSERT_NO_THROW(check_rt_info(f)); + ASSERT_TRUE(f->get_output_partial_shape(0).is_static()) << "Shape " << f->get_output_partial_shape(0) << " should be static"; + } + + { + auto boxes = std::make_shared(element::f32, Shape{1, 1000, 4}); + auto scores = std::make_shared(element::f32, Shape{1, 1, 1000}); + auto max_output_boxes_per_class = opset1::Constant::create(element::i32, Shape{1}, {10}); + auto iou_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.75}); + auto score_threshold = opset1::Constant::create(element::f32, Shape{1}, {0.7}); + auto nms = std::make_shared(boxes, scores, max_output_boxes_per_class, + iou_threshold, score_threshold, 0, true, element::i32); + + f_ref = std::make_shared(NodeVector{nms}, ParameterVector{boxes, scores}); + ASSERT_TRUE(f_ref->get_output_partial_shape(0).is_static()) << "Shape " << f_ref->get_output_partial_shape(0) << " should be static"; + } + + auto res = compare_functions(f, f_ref); + ASSERT_TRUE(res.first) << res.second; +} \ No newline at end of file