From 29d82b7a9ad2ac2004ffbf52cde23ec2f685fc41 Mon Sep 17 00:00:00 2001 From: Andrew Bakalin Date: Thu, 24 Dec 2020 12:27:10 +0300 Subject: [PATCH] [IE][VPU]: Fix loading previous NMS versions (#3696) * Description: currently IRs with NMS version < 5 don't work because conversion of previous NMS versions to NMS-5 happens after DTS (in opset1 to legacy conversion), while for Myriad Plugin it's necessary to do so at the very beginning of ngraph conversion pipeline. --- .../src/frontend/frontend.cpp | 4 + .../single_layer_tests/static_shape_nms.cpp | 96 ++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp index 91c2ffb65fadbf..928c33c99d1dc9 100644 --- a/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp +++ b/inference-engine/src/vpu/graph_transformer/src/frontend/frontend.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,9 @@ ie::ICNNNetwork::Ptr FrontEnd::convertNetwork(ie::ICNNNetwork& network) { manager.register_pass<::ngraph::pass::InitNodeInfo>(); // WA: ConvertPriorBox must be executed before the 1st ConstantFolding pass manager.register_pass<::ngraph::pass::ConvertPriorBox>(); + manager.register_pass(); + manager.register_pass(); + manager.register_pass(); manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/inference-engine/tests/functional/plugin/myriad/single_layer_tests/static_shape_nms.cpp b/inference-engine/tests/functional/plugin/myriad/single_layer_tests/static_shape_nms.cpp index 2d471918c8da6e..8455e4f4ec1111 100644 --- a/inference-engine/tests/functional/plugin/myriad/single_layer_tests/static_shape_nms.cpp +++ b/inference-engine/tests/functional/plugin/myriad/single_layer_tests/static_shape_nms.cpp @@ -6,6 +6,8 @@ #include #include +#include + #include #include "vpu/ngraph/operations/static_shape_non_maximum_suppression.hpp" @@ -28,7 +30,7 @@ using StaticShapeNMSTestParam = std::tuple< namespace LayerTestsDefinitions { class StaticShapeNMSLayerTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { + virtual public LayerTestsUtils::LayerTestsCommon { public: static std::string getTestCaseName(const testing::TestParamInfo& obj) { StaticShapeNMSParam NMSParams; @@ -120,4 +122,96 @@ INSTANTIATE_TEST_CASE_P(DISABLED_accuracy, StaticShapeNMSLayerTest, ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)), StaticShapeNMSLayerTest::getTestCaseName); +class PreviousNMStoStaticShapeNMS : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +protected: + virtual std::shared_ptr createNMS( + const ngraph::Output& inputBoxes, + const ngraph::Output& inputScores, + const ngraph::Output& maxOutputBoxesPerClassConst, + const ngraph::Output& iouThresholdConst, + const ngraph::Output& scoreThresholdConst) = 0; + + void SetUp() override { + targetDevice = this->GetParam(); + + const auto inputBoxes = std::make_shared( + ngraph::element::f32, ngraph::Shape({static_cast(1), static_cast(10), 4})); + const auto inputScores = std::make_shared( + ngraph::element::f32, ngraph::Shape({static_cast(1), static_cast(5), static_cast(10)})); + const auto maxOutputBoxesPerClassConst = std::make_shared( + ngraph::element::i64, ngraph::Shape{}, 10); + const auto iouThresholdConst = std::make_shared( + ngraph::element::f32, ngraph::Shape{}, .0f); + const auto scoreThresholdConst = std::make_shared( + ngraph::element::f32, ngraph::Shape{}, .0f); + + const auto nms = createNMS(inputBoxes, inputScores, maxOutputBoxesPerClassConst, iouThresholdConst, scoreThresholdConst); + + function = std::make_shared(nms->outputs(), ngraph::ParameterVector{inputBoxes, inputScores}); + } +}; + +class NMS1toStaticShapeNMS : public PreviousNMStoStaticShapeNMS { +protected: + std::shared_ptr createNMS( + const ngraph::Output& inputBoxes, + const ngraph::Output& inputScores, + const ngraph::Output& maxOutputBoxesPerClassConst, + const ngraph::Output& iouThresholdConst, + const ngraph::Output& scoreThresholdConst) override { + return std::make_shared( + inputBoxes, inputScores, maxOutputBoxesPerClassConst, iouThresholdConst, scoreThresholdConst, + ngraph::opset1::NonMaxSuppression::BoxEncodingType::CORNER, false); + } +}; + +TEST_P(NMS1toStaticShapeNMS, PreviousNMSCanBeLoaded) { + ASSERT_NO_THROW(LoadNetwork()); +} + +INSTANTIATE_TEST_CASE_P(smoke_NetworkLoad, NMS1toStaticShapeNMS, + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)); + +class NMS3toStaticShapeNMS : public PreviousNMStoStaticShapeNMS { + std::shared_ptr createNMS( + const ngraph::Output& inputBoxes, + const ngraph::Output& inputScores, + const ngraph::Output& maxOutputBoxesPerClassConst, + const ngraph::Output& iouThresholdConst, + const ngraph::Output& scoreThresholdConst) override { + return std::make_shared( + inputBoxes, inputScores, maxOutputBoxesPerClassConst, iouThresholdConst, scoreThresholdConst, + ngraph::opset3::NonMaxSuppression::BoxEncodingType::CORNER, false); + } +}; + +TEST_P(NMS3toStaticShapeNMS, PreviousNMSCanBeLoaded) { + ASSERT_NO_THROW(LoadNetwork()); +} + +INSTANTIATE_TEST_CASE_P(smoke_NetworkLoad, NMS3toStaticShapeNMS, + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)); + +class NMS4toStaticShapeNMS : public PreviousNMStoStaticShapeNMS { +protected: + std::shared_ptr createNMS( + const ngraph::Output& inputBoxes, + const ngraph::Output& inputScores, + const ngraph::Output& maxOutputBoxesPerClassConst, + const ngraph::Output& iouThresholdConst, + const ngraph::Output& scoreThresholdConst) override { + return std::make_shared( + inputBoxes, inputScores, maxOutputBoxesPerClassConst, iouThresholdConst, scoreThresholdConst, + ngraph::opset4::NonMaxSuppression::BoxEncodingType::CORNER, false); + } +}; + +TEST_P(NMS4toStaticShapeNMS, PreviousNMSCanBeLoaded) { + ASSERT_NO_THROW(LoadNetwork()); +} + +INSTANTIATE_TEST_CASE_P(smoke_NetworkLoad, NMS4toStaticShapeNMS, + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)); + } // namespace LayerTestsDefinitions