Skip to content

Commit

Permalink
[IE][VPU]: Fix loading previous NMS versions (#3696)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
andreybakalin97 authored Dec 24, 2020
1 parent ad3405e commit 29d82b7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <ngraph/opsets/opset5.hpp>
#include <transformations/opset_conversions/convert_opset3_to_opset2.hpp>
#include <transformations/opset_conversions/convert_opset2_to_opset1.hpp>
#include <transformations/op_conversions/convert_previous_nms_to_nms_5.hpp>
#include <legacy/transformations/convert_opset1_to_legacy/convert_opset1_to_legacy.hpp>
#include <legacy/transformations/convert_opset1_to_legacy/convert_prior_to_ie_prior.hpp>
#include <transformations/common_optimizations/common_optimizations.hpp>
Expand Down Expand Up @@ -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<ngraph::pass::ConvertNMS1ToNMS5>();
manager.register_pass<ngraph::pass::ConvertNMS3ToNMS5>();
manager.register_pass<ngraph::pass::ConvertNMS4ToNMS5>();
manager.register_pass<ngraph::pass::CommonOptimizations>();
manager.register_pass<vpu::DynamicToStaticShape>();
manager.register_pass<vpu::EliminateShapeOfAfterDSR>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <functional_test_utils/blob_utils.hpp>

#include <ngraph/opsets/opset3.hpp>
#include <ngraph/opsets/opset4.hpp>

#include <ngraph/op/non_max_suppression.hpp>
#include "vpu/ngraph/operations/static_shape_non_maximum_suppression.hpp"

Expand All @@ -28,7 +30,7 @@ using StaticShapeNMSTestParam = std::tuple<
namespace LayerTestsDefinitions {

class StaticShapeNMSLayerTest : public testing::WithParamInterface<StaticShapeNMSTestParam>,
virtual public LayerTestsUtils::LayerTestsCommon {
virtual public LayerTestsUtils::LayerTestsCommon {
public:
static std::string getTestCaseName(const testing::TestParamInfo<StaticShapeNMSTestParam>& obj) {
StaticShapeNMSParam NMSParams;
Expand Down Expand Up @@ -120,4 +122,96 @@ INSTANTIATE_TEST_CASE_P(DISABLED_accuracy, StaticShapeNMSLayerTest,
::testing::Values(CommonTestUtils::DEVICE_MYRIAD)),
StaticShapeNMSLayerTest::getTestCaseName);

class PreviousNMStoStaticShapeNMS : public testing::WithParamInterface<LayerTestsUtils::TargetDevice>,
virtual public LayerTestsUtils::LayerTestsCommon {
protected:
virtual std::shared_ptr<ngraph::Node> createNMS(
const ngraph::Output<ngraph::Node>& inputBoxes,
const ngraph::Output<ngraph::Node>& inputScores,
const ngraph::Output<ngraph::Node>& maxOutputBoxesPerClassConst,
const ngraph::Output<ngraph::Node>& iouThresholdConst,
const ngraph::Output<ngraph::Node>& scoreThresholdConst) = 0;

void SetUp() override {
targetDevice = this->GetParam();

const auto inputBoxes = std::make_shared<ngraph::opset3::Parameter>(
ngraph::element::f32, ngraph::Shape({static_cast<size_t>(1), static_cast<size_t>(10), 4}));
const auto inputScores = std::make_shared<ngraph::opset3::Parameter>(
ngraph::element::f32, ngraph::Shape({static_cast<size_t>(1), static_cast<size_t>(5), static_cast<size_t>(10)}));
const auto maxOutputBoxesPerClassConst = std::make_shared<ngraph::opset3::Constant>(
ngraph::element::i64, ngraph::Shape{}, 10);
const auto iouThresholdConst = std::make_shared<ngraph::opset3::Constant>(
ngraph::element::f32, ngraph::Shape{}, .0f);
const auto scoreThresholdConst = std::make_shared<ngraph::opset3::Constant>(
ngraph::element::f32, ngraph::Shape{}, .0f);

const auto nms = createNMS(inputBoxes, inputScores, maxOutputBoxesPerClassConst, iouThresholdConst, scoreThresholdConst);

function = std::make_shared<ngraph::Function>(nms->outputs(), ngraph::ParameterVector{inputBoxes, inputScores});
}
};

class NMS1toStaticShapeNMS : public PreviousNMStoStaticShapeNMS {
protected:
std::shared_ptr<ngraph::Node> createNMS(
const ngraph::Output<ngraph::Node>& inputBoxes,
const ngraph::Output<ngraph::Node>& inputScores,
const ngraph::Output<ngraph::Node>& maxOutputBoxesPerClassConst,
const ngraph::Output<ngraph::Node>& iouThresholdConst,
const ngraph::Output<ngraph::Node>& scoreThresholdConst) override {
return std::make_shared<ngraph::opset1::NonMaxSuppression>(
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<ngraph::Node> createNMS(
const ngraph::Output<ngraph::Node>& inputBoxes,
const ngraph::Output<ngraph::Node>& inputScores,
const ngraph::Output<ngraph::Node>& maxOutputBoxesPerClassConst,
const ngraph::Output<ngraph::Node>& iouThresholdConst,
const ngraph::Output<ngraph::Node>& scoreThresholdConst) override {
return std::make_shared<ngraph::opset3::NonMaxSuppression>(
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<ngraph::Node> createNMS(
const ngraph::Output<ngraph::Node>& inputBoxes,
const ngraph::Output<ngraph::Node>& inputScores,
const ngraph::Output<ngraph::Node>& maxOutputBoxesPerClassConst,
const ngraph::Output<ngraph::Node>& iouThresholdConst,
const ngraph::Output<ngraph::Node>& scoreThresholdConst) override {
return std::make_shared<ngraph::opset4::NonMaxSuppression>(
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

0 comments on commit 29d82b7

Please sign in to comment.