[IE][VPU][NGraph] Move dynamic NMS from common to vpu folder (#1409)

* [IE][VPU]: Moves UpgradeNMS4ToNMSDynamic transformation into myriad plugin

* [IE][VPU]: Moves UpgradeNMS4ToNMSDynamic from common to vpu folder

* [IE][VPU]: Moves Dynamic NMS from common folder to vpu

* [VPU]: Makes NMS conversion unconditional

* [VPU][NGraph]: Changes dynamic NMS base class from v3 to v4

* [VPU]: Moves NMS4toDynamic transformation before common optimization
This commit is contained in:
Andrew Bakalin authored and GitHub committed 2020-07-23 10:23:35 +03:00
1 parent c69591c0b7
commit dce1063526
15 files changed
+236 -241

No files matched your search

@@ -17,7 +17,6 @@
// This pass must be called first in pipeline
NGRAPH_PASS(InitNodeInfo, ::ngraph::pass)
NGRAPH_PASS(RemoveFilteringBoxesBySize, ::ngraph::pass) // Resolves dynamism (replaces NonZero), CF needed
NGRAPH_PASS(UpgradeNMS4ToNMSDynamic, ::ngraph::pass) // replaces v4::NMS with dynamic::NMS(always dyn output shape) if function has opset3::NonZero operation
NGRAPH_PASS(ConstantFolding, ::ngraph::pass)
NGRAPH_PASS(StridedSliceOptimization, ::ngraph::pass) // depends on CF
NGRAPH_PASS(NopElimination, ::ngraph::pass) // may introduce fake dynamism
@@ -1,40 +0,0 @@
// Copyright (C) 2018-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <vector>
#include <memory>
#include <transformations_visibility.hpp>
#include <ngraph/pass/graph_rewrite.hpp>
namespace ngraph {
namespace pass {
class TRANSFORMATIONS_API UpgradeNMS4ToNMSDynamic;
} // namespace pass
} // namespace ngraph
/*
* Description:
* UpgradeNMS4ToNMSDynamic transformation upgrades NonMaxSuppression operations from v3 version to dynamic
* in case function has at least one NonZero operation (dynamism marker).
* NMS dynamic always has dynamic output
*/
class ngraph::pass::UpgradeNMS4ToNMSDynamic: public ngraph::pass::GraphRewrite {
public:
UpgradeNMS4ToNMSDynamic() : GraphRewrite() {
upgrade_nms4_to_nms_dynamic();
}
bool run_on_function(std::shared_ptr<ngraph::Function> f) override;
private:
void upgrade_nms4_to_nms_dynamic();
};
@@ -9,7 +9,6 @@
#include "transformations/optimize_strided_slice.hpp"
#include "transformations/convert_scatter_elements_to_scatter.hpp"
#include "transformations/remove_filtering_boxes_by_size.hpp"
#include "transformations/convert_nms_4_to_nms_dynamic.hpp"
#include "transformations/init_node_info.hpp"
#include <ngraph/pass/manager.hpp>
@@ -0,0 +1,61 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "ngraph/op/non_max_suppression.hpp"
namespace ngraph { namespace vpu { namespace op {
class DynamicNonMaxSuppression : public ngraph::op::v4::NonMaxSuppression {
public:
static constexpr NodeTypeInfo type_info{"DynamicNonMaxSuppression", 0};
const NodeTypeInfo& get_type_info() const override { return type_info; }
DynamicNonMaxSuppression() = default;
/// \brief Constructs a DynamicNonMaxSuppression operation.
///
/// \param boxes Node producing the box coordinates
/// \param scores Node producing the box scores
/// \param max_output_boxes_per_class Node producing maximum number of boxes to be
/// selected per class
/// \param iou_threshold Node producing intersection over union threshold
/// \param score_threshold Node producing minimum score threshold
/// \param box_encoding Specifies the format of boxes data encoding
/// \param sort_result_descending Specifies whether it is necessary to sort selected
/// boxes across batches
/// \param output_type Specifies the output tensor type
DynamicNonMaxSuppression(const Output<Node>& boxes,
const Output<Node>& scores,
const Output<Node>& max_output_boxes_per_class,
const Output<Node>& iou_threshold,
const Output<Node>& score_threshold,
const BoxEncodingType box_encoding = BoxEncodingType::CORNER,
const bool sort_result_descending = true,
const ngraph::element::Type& output_type = ngraph::element::i64);
/// \brief Constructs a DynamicNonMaxSuppression operation with default values for the last
/// 3 inputs
///
/// \param boxes Node producing the box coordinates
/// \param scores Node producing the box coordinates
/// \param box_encoding Specifies the format of boxes data encoding
/// \param sort_result_descending Specifies whether it is necessary to sort selected
/// boxes across batches
/// \param output_type Specifies the output tensor type
DynamicNonMaxSuppression(const Output<Node>& boxes,
const Output<Node>& scores,
const BoxEncodingType box_encoding = BoxEncodingType::CORNER,
const bool sort_result_descending = true,
const ngraph::element::Type& output_type = ngraph::element::i64);
void validate_and_infer_types() override;
std::shared_ptr<Node>
clone_with_new_inputs(const OutputVector& new_args) const override;
};
} // namespace op
} // namespace vpu
} // namespace ngraph
@@ -0,0 +1,21 @@
// Copyright (C) 2018-2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <ngraph/pass/graph_rewrite.hpp>
namespace vpu {
class UpgradeNMS4ToNMSDynamic : public ngraph::pass::GraphRewrite {
public:
UpgradeNMS4ToNMSDynamic() : GraphRewrite() {
upgrade_nms4_to_nms_dynamic();
}
private:
void upgrade_nms4_to_nms_dynamic();
};
} // namespace vpu
@@ -41,7 +41,7 @@ void throwFormat(const char* fileName, int lineNumber, const char* messageFormat
#define VPU_THROW_UNLESS(condition, ...) \
do { \
if (!(condition)) { \
vpu::details::throwFormat<vpu::details::VPUException>(__FILE__, __LINE__, __VA_ARGS__); \
::vpu::details::throwFormat<::vpu::details::VPUException>(__FILE__, __LINE__, __VA_ARGS__); \
} \
} while (false)
@@ -0,0 +1,89 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "vpu/ngraph/operations/dynamic_non_max_suppression.hpp"
#include "vpu/utils/error.hpp"
#include "ngraph/opsets/opset3.hpp"
#include "ngraph/evaluator.hpp"
namespace ngraph { namespace vpu { namespace op {
constexpr NodeTypeInfo DynamicNonMaxSuppression::type_info;
DynamicNonMaxSuppression::DynamicNonMaxSuppression(
const Output<Node>& boxes,
const Output<Node>& scores,
const Output<Node>& max_output_boxes_per_class,
const Output<Node>& iou_threshold,
const Output<Node>& score_threshold,
const BoxEncodingType box_encoding,
const bool sort_result_descending,
const element::Type& output_type)
: ngraph::op::v4::NonMaxSuppression(boxes,
scores,
max_output_boxes_per_class,
iou_threshold,
score_threshold,
box_encoding,
sort_result_descending,
output_type) {
constructor_validate_and_infer_types();
}
DynamicNonMaxSuppression::DynamicNonMaxSuppression(
const Output<Node>& boxes,
const Output<Node>& scores,
const BoxEncodingType box_encoding,
const bool sort_result_descending,
const element::Type& output_type)
: ngraph::op::v4::NonMaxSuppression(boxes,
scores,
ngraph::op::Constant::create(element::i64, Shape{}, {0}),
ngraph::op::Constant::create(element::f32, Shape{}, {.0f}),
ngraph::op::Constant::create(element::f32, Shape{}, {.0f}),
box_encoding,
sort_result_descending,
output_type) {
constructor_validate_and_infer_types();
}
std::shared_ptr<Node> DynamicNonMaxSuppression::clone_with_new_inputs(const OutputVector& new_args) const {
check_new_args_count(this, new_args);
NODE_VALIDATION_CHECK(this,
new_args.size() >= 2 && new_args.size() <= 5,
"Number of inputs must be 2, 3, 4 or 5");
const auto& arg2 = new_args.size() > 2
? new_args.at(2)
: ngraph::op::Constant::create(element::i32, Shape{}, {0});
const auto& arg3 = new_args.size() > 3
? new_args.at(3)
: ngraph::op::Constant::create(element::f32, Shape{}, {.0f});
const auto& arg4 = new_args.size() > 4
? new_args.at(4)
: ngraph::op::Constant::create(element::f32, Shape{}, {.0f});
return std::make_shared<DynamicNonMaxSuppression>(new_args.at(0),
new_args.at(1),
arg2,
arg3,
arg4,
m_box_encoding,
m_sort_result_descending,
m_output_type);
}
void DynamicNonMaxSuppression::validate_and_infer_types() {
ngraph::op::v4::NonMaxSuppression::validate_and_infer_types();
// NonMaxSuppression produces triplets
// that have the following format: [batch_index, class_index, box_index]
set_output_type(0, m_output_type, PartialShape{Dimension::dynamic(), 3});
}
} // namespace op
} // namespace vpu
} // namespace ngraph
@@ -2,38 +2,39 @@
// SPDX-License-Identifier: Apache-2.0
//
#include <memory>
#include <vector>
#include "vpu/ngraph/transformations/convert_nms_4_to_nms_dynamic.hpp"
#include <vpu/ngraph/operations/dynamic_non_max_suppression.hpp>
#include <ngraph/graph_util.hpp>
#include <ngraph/opsets/opset4.hpp>
#include <ngraph/rt_info.hpp>
#include <transformations/utils/utils.hpp>
#include "transformations/convert_nms_4_to_nms_dynamic.hpp"
#include <memory>
#include <vector>
void ngraph::pass::UpgradeNMS4ToNMSDynamic::upgrade_nms4_to_nms_dynamic() {
auto boxes = std::make_shared<pattern::op::Label>(element::f32, Shape{1, 1000, 4});
auto scores = std::make_shared<pattern::op::Label>(element::f32, Shape{1, 1, 1000});
auto max_output_boxes_per_class = ngraph::opset4::Constant::create(element::i64, Shape{}, {10});
auto iou_threshold = ngraph::opset4::Constant::create(element::f32, Shape{}, {0.75});
auto score_threshold = ngraph::opset4::Constant::create(element::f32, Shape{}, {0.7});
void vpu::UpgradeNMS4ToNMSDynamic::upgrade_nms4_to_nms_dynamic() {
auto boxes = std::make_shared<ngraph::pattern::op::Label>(ngraph::element::f32, ngraph::Shape{1, 1000, 4});
auto scores = std::make_shared<ngraph::pattern::op::Label>(ngraph::element::f32, ngraph::Shape{1, 1, 1000});
auto max_output_boxes_per_class = ngraph::opset4::Constant::create(ngraph::element::i64, ngraph::Shape{}, {10});
auto iou_threshold = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.75});
auto score_threshold = ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {0.7});
auto nms = std::make_shared<ngraph::opset4::NonMaxSuppression>(boxes, scores, max_output_boxes_per_class,
iou_threshold, score_threshold);
ngraph::graph_rewrite_callback callback = [](pattern::Matcher &m) {
ngraph::graph_rewrite_callback callback = [](ngraph::pattern::Matcher &m) {
auto nms_4 = std::dynamic_pointer_cast<ngraph::opset4::NonMaxSuppression>(m.get_match_root());
if (!nms_4) {
return false;
}
const auto box_encoding = static_cast<const op::dynamic::NonMaxSuppression::BoxEncodingType>(nms_4->get_box_encoding());
const auto box_encoding = nms_4->get_box_encoding();
const auto new_args = nms_4->input_values();
const auto& arg2 = new_args.size() > 2 ? new_args.at(2) : ngraph::opset4::Constant::create(element::i32, Shape{}, {0});
const auto& arg3 = new_args.size() > 3 ? new_args.at(3) : ngraph::opset4::Constant::create(element::f32, Shape{}, {.0f});
const auto& arg4 = new_args.size() > 4 ? new_args.at(4) : ngraph::opset4::Constant::create(element::f32, Shape{}, {.0f});
const auto& arg2 = new_args.size() > 2 ? new_args.at(2) : ngraph::opset4::Constant::create(ngraph::element::i32, ngraph::Shape{}, {0});
const auto& arg3 = new_args.size() > 3 ? new_args.at(3) : ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {.0f});
const auto& arg4 = new_args.size() > 4 ? new_args.at(4) : ngraph::opset4::Constant::create(ngraph::element::f32, ngraph::Shape{}, {.0f});
const auto nms_dynamic = std::make_shared<op::dynamic::NonMaxSuppression>(
const auto nms_dynamic = std::make_shared<ngraph::vpu::op::DynamicNonMaxSuppression>(
new_args.at(0),
new_args.at(1),
arg2,
@@ -50,12 +51,5 @@ void ngraph::pass::UpgradeNMS4ToNMSDynamic::upgrade_nms4_to_nms_dynamic() {
};
auto m = std::make_shared<ngraph::pattern::Matcher>(nms, "UpgradeNMS4ToDynamic");
this->add_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE);
}
bool ngraph::pass::UpgradeNMS4ToNMSDynamic::run_on_function(std::shared_ptr<ngraph::Function> f) {
if (ngraph::op::util::has_op_with_type<ngraph::opset4::NonZero>(f)) {
return GraphRewrite::run_on_function(f);
}
return false;
this->add_matcher(m, callback, ngraph::pass::PassProperty::CHANGE_DYNAMIC_STATE);
}
@@ -24,6 +24,7 @@
#include "vpu/utils/error.hpp"
#include "ngraph/opsets/opset3.hpp"
#include "vpu/ngraph/operations/dynamic_non_max_suppression.hpp"
namespace vpu {
@@ -57,46 +58,46 @@ bool validateStaticShapes(const ngraph::Function& function) {
const Transformations& getDefaultTransformations() {
static const Transformations transformations = {
{ngraph::opset3::Add::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Multiply::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Subtract::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::VariadicSplit::type_info, dynamicToStaticShapeVariadicSplit},
{ngraph::opset3::Divide::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Equal::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Greater::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Power::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::op::dynamic::NonMaxSuppression::type_info, dynamicToStaticNonMaxSuppression},
{ngraph::opset3::NonZero::type_info, dynamicToStaticShapeNonZero},
{ngraph::opset3::TopK::type_info, dynamicToStaticShapeTopK},
{ngraph::opset3::Transpose::type_info, dynamicToStaticShapeTranspose},
{ngraph::opset3::Concat::type_info, dynamicToStaticShapeConcat},
{ngraph::opset3::Convert::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Clamp::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Floor::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Log::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Relu::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::ScatterUpdate::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Sigmoid::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Softmax::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Exp::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Sqrt::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::StridedSlice::type_info, dynamicToStaticShapeStridedSlice},
{ngraph::opset3::Squeeze::type_info, dynamicToStaticShapeSqueeze},
{ngraph::opset3::Gather::type_info, dynamicToStaticShapeGather},
{ngraph::opset3::Unsqueeze::type_info, dynamicToStaticShapeUnsqueeze},
{ngraph::opset3::ROIAlign::type_info, dynamicToStaticShapeROIAlign},
{ngraph::opset3::Reshape::type_info, dynamicToStaticShapeReshape},
{ngraph::opset3::Broadcast::type_info, dynamicToStaticShapeBroadcast},
{ngraph::opset3::MatMul::type_info, dynamicToStaticShapeMatMul},
{ngraph::opset3::Add::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Multiply::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Subtract::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::VariadicSplit::type_info, dynamicToStaticShapeVariadicSplit},
{ngraph::opset3::Divide::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Equal::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Greater::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::opset3::Power::type_info, dynamicToStaticShapeBinaryEltwise},
{ngraph::vpu::op::DynamicNonMaxSuppression::type_info, dynamicToStaticNonMaxSuppression},
{ngraph::opset3::NonZero::type_info, dynamicToStaticShapeNonZero},
{ngraph::opset3::TopK::type_info, dynamicToStaticShapeTopK},
{ngraph::opset3::Transpose::type_info, dynamicToStaticShapeTranspose},
{ngraph::opset3::Concat::type_info, dynamicToStaticShapeConcat},
{ngraph::opset3::Convert::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Clamp::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Floor::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Log::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Relu::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::ScatterUpdate::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Sigmoid::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Softmax::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Exp::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::Sqrt::type_info, dynamicToStaticUnaryElementwise},
{ngraph::opset3::StridedSlice::type_info, dynamicToStaticShapeStridedSlice},
{ngraph::opset3::Squeeze::type_info, dynamicToStaticShapeSqueeze},
{ngraph::opset3::Gather::type_info, dynamicToStaticShapeGather},
{ngraph::opset3::Unsqueeze::type_info, dynamicToStaticShapeUnsqueeze},
{ngraph::opset3::ROIAlign::type_info, dynamicToStaticShapeROIAlign},
{ngraph::opset3::Reshape::type_info, dynamicToStaticShapeReshape},
{ngraph::opset3::Broadcast::type_info, dynamicToStaticShapeBroadcast},
{ngraph::opset3::MatMul::type_info, dynamicToStaticShapeMatMul},
// reduction
{ngraph::opset3::ReduceLogicalAnd::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceLogicalOr::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceMax::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceMean::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceMin::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceProd::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceSum::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceLogicalOr::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceMax::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceMean::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceMin::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceProd::type_info, dynamicToStaticShapeReduce},
{ngraph::opset3::ReduceSum::type_info, dynamicToStaticShapeReduce},
};
return transformations;
}
@@ -5,6 +5,7 @@
#include "vpu/ngraph/transformations/dynamic_to_static_shape_non_max_suppression.hpp"
#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp"
#include "vpu/ngraph/operations/dynamic_non_max_suppression.hpp"
#include <vpu/utils/error.hpp>
#include "ngraph/graph_util.hpp"
@@ -16,9 +17,9 @@
namespace vpu {
void dynamicToStaticNonMaxSuppression(std::shared_ptr<ngraph::Node> node) {
auto nms_dynamic = std::dynamic_pointer_cast<ngraph::op::dynamic::NonMaxSuppression>(node);
auto nms_dynamic = std::dynamic_pointer_cast<ngraph::vpu::op::DynamicNonMaxSuppression>(node);
VPU_THROW_UNLESS(nms_dynamic, "dynamicToStaticNonMaxSuppression transformation for {} of type {} expects {} as node for replacement",
node->get_friendly_name(), node->get_type_info(), ngraph::op::dynamic::NonMaxSuppression::type_info);
node->get_friendly_name(), node->get_type_info(), ngraph::vpu::op::DynamicNonMaxSuppression::type_info);
auto staticShapeNMS = std::make_shared<ngraph::vpu::op::StaticShapeNonMaxSuppression>(
nms_dynamic->input_value(0),
@@ -17,6 +17,7 @@
#include <vpu/utils/profiling.hpp>
#include <vpu/utils/error.hpp>
#include <transformations/common_optimizations/common_optimizations.hpp>
#include <vpu/ngraph/transformations/convert_nms_4_to_nms_dynamic.hpp>
#include "vpu/ngraph/transformations/dynamic_to_static_shape.hpp"
#include "vpu/ngraph/transformations/eliminate_shapeof_after_dsr.hpp"
@@ -41,6 +42,7 @@ ExecutableNetworkInternal::Ptr Engine::LoadExeNetworkImpl(
auto clonedNetwork = cloneNetwork(network);
if (auto function = clonedNetwork->getFunction()) {
ngraph::op::GenericIE::DisableReshape noReshape(function);
vpu::UpgradeNMS4ToNMSDynamic().run_on_function(function);
ngraph::pass::CommonOptimizations().run_on_function(function);
vpu::DynamicToStaticShape().transform(function);
vpu::EliminateShapeOfAfterDSR().run_on_function(function);
@@ -6,6 +6,7 @@
#include <ngraph_functions/utils/ngraph_helpers.hpp>
#include <ngraph/opsets/opset3.hpp>
#include <vpu/ngraph/operations/dynamic_shape_resolver.hpp>
#include <vpu/ngraph/operations/dynamic_non_max_suppression.hpp>
#include <vpu/ngraph/transformations/dynamic_to_static_shape.hpp>
#include <vpu/ngraph/transformations/dynamic_to_static_shape_non_max_suppression.hpp>
#include <vpu/ngraph/operations/static_shape_non_maximum_suppression.hpp>
@@ -56,7 +57,7 @@ protected:
const auto dims = std::make_shared<ngraph::opset3::Parameter>(ngraph::element::i64, ngraph::Shape{3});
const auto dsr = std::make_shared<ngraph::vpu::op::DynamicShapeResolver>(scores, dims);
const auto node = std::make_shared<ngraph::op::dynamic::NonMaxSuppression>(
const auto node = std::make_shared<ngraph::vpu::op::DynamicNonMaxSuppression>(
boxes, dsr, max_output_boxes_per_class, iou_threshold, score_threshold);
auto outputShape = node->get_output_partial_shape(0);
@@ -5,6 +5,7 @@
#include <functional_test_utils/layer_test_utils.hpp>
#include <ngraph_functions/builders.hpp>
#include <vpu/ngraph/operations/dynamic_shape_resolver.hpp>
#include <vpu/ngraph/operations/dynamic_non_max_suppression.hpp>
namespace {
@@ -48,7 +49,7 @@ protected:
const auto dims = std::make_shared<ngraph::opset3::Parameter>(ngraph::element::i64, ngraph::Shape{3});
const auto dsr = std::make_shared<ngraph::vpu::op::DynamicShapeResolver>(scores, dims);
const auto node = std::make_shared<ngraph::op::dynamic::NonMaxSuppression>(
const auto node = std::make_shared<ngraph::vpu::op::DynamicNonMaxSuppression>(
boxes, dsr, max_output_boxes_per_class, iou_threshold, score_threshold);
const auto result = std::make_shared<ngraph::opset3::Result>(node);
@@ -530,83 +530,3 @@ void op::v4::NonMaxSuppression::validate_and_infer_types()
}
set_output_type(0, m_output_type, out_shape);
}
// ------------------------------ dynamic ------------------------------
constexpr NodeTypeInfo op::dynamic::NonMaxSuppression::type_info;
op::dynamic::NonMaxSuppression::NonMaxSuppression(
const Output<Node>& boxes,
const Output<Node>& scores,
const Output<Node>& max_output_boxes_per_class,
const Output<Node>& iou_threshold,
const Output<Node>& score_threshold,
const op::dynamic::NonMaxSuppression::BoxEncodingType box_encoding,
const bool sort_result_descending,
const element::Type& output_type)
: op::v3::NonMaxSuppression(boxes,
scores,
max_output_boxes_per_class,
iou_threshold,
score_threshold,
box_encoding,
sort_result_descending,
output_type)
{
constructor_validate_and_infer_types();
}
op::dynamic::NonMaxSuppression::NonMaxSuppression(
const Output<Node>& boxes,
const Output<Node>& scores,
const op::dynamic::NonMaxSuppression::BoxEncodingType box_encoding,
const bool sort_result_descending,
const element::Type& output_type)
: op::v3::NonMaxSuppression(boxes,
scores,
op::Constant::create(element::i64, Shape{}, {0}),
op::Constant::create(element::f32, Shape{}, {.0f}),
op::Constant::create(element::f32, Shape{}, {.0f}),
box_encoding,
sort_result_descending,
output_type)
{
constructor_validate_and_infer_types();
}
shared_ptr<Node>
op::dynamic::NonMaxSuppression::clone_with_new_inputs(const OutputVector& new_args) const
{
check_new_args_count(this, new_args);
NODE_VALIDATION_CHECK(this,
new_args.size() >= 2 && new_args.size() <= 5,
"Number of inputs must be 2, 3, 4 or 5");
const auto& arg2 = new_args.size() > 2
? new_args.at(2)
: ngraph::op::Constant::create(element::i32, Shape{}, {0});
const auto& arg3 = new_args.size() > 3
? new_args.at(3)
: ngraph::op::Constant::create(element::f32, Shape{}, {.0f});
const auto& arg4 = new_args.size() > 4
? new_args.at(4)
: ngraph::op::Constant::create(element::f32, Shape{}, {.0f});
return std::make_shared<op::dynamic::NonMaxSuppression>(new_args.at(0),
new_args.at(1),
arg2,
arg3,
arg4,
m_box_encoding,
m_sort_result_descending,
m_output_type);
}
void op::dynamic::NonMaxSuppression::validate_and_infer_types()
{
op::v3::NonMaxSuppression::validate_and_infer_types();
// NonMaxSuppression produces triplets
// that have the following format: [batch_index, class_index, box_index]
set_output_type(0, m_output_type, PartialShape{Dimension::dynamic(), 3});
}
@@ -235,60 +235,6 @@ namespace ngraph
clone_with_new_inputs(const OutputVector& new_args) const override;
};
} // namespace v4
namespace dynamic
{
/// \brief NonMaxSuppression operation
///
class NGRAPH_API NonMaxSuppression : public op::v3::NonMaxSuppression
{
public:
static constexpr NodeTypeInfo type_info{"NonMaxSuppression", 99};
const NodeTypeInfo& get_type_info() const override { return type_info; }
NonMaxSuppression() = default;
/// \brief Constructs a NonMaxSuppression operation.
///
/// \param boxes Node producing the box coordinates
/// \param scores Node producing the box scores
/// \param max_output_boxes_per_class Node producing maximum number of boxes to be
/// selected per class
/// \param iou_threshold Node producing intersection over union threshold
/// \param score_threshold Node producing minimum score threshold
/// \param box_encoding Specifies the format of boxes data encoding
/// \param sort_result_descending Specifies whether it is necessary to sort selected
/// boxes across batches
/// \param output_type Specifies the output tensor type
NonMaxSuppression(const Output<Node>& boxes,
const Output<Node>& scores,
const Output<Node>& max_output_boxes_per_class,
const Output<Node>& iou_threshold,
const Output<Node>& score_threshold,
const BoxEncodingType box_encoding = BoxEncodingType::CORNER,
const bool sort_result_descending = true,
const ngraph::element::Type& output_type = ngraph::element::i64);
/// \brief Constructs a NonMaxSuppression operation with default values for the last
/// 3 inputs
///
/// \param boxes Node producing the box coordinates
/// \param scores Node producing the box coordinates
/// \param box_encoding Specifies the format of boxes data encoding
/// \param sort_result_descending Specifies whether it is necessary to sort selected
/// boxes across batches
/// \param output_type Specifies the output tensor type
NonMaxSuppression(const Output<Node>& boxes,
const Output<Node>& scores,
const BoxEncodingType box_encoding = BoxEncodingType::CORNER,
const bool sort_result_descending = true,
const ngraph::element::Type& output_type = ngraph::element::i64);
void validate_and_infer_types() override;
std::shared_ptr<Node>
clone_with_new_inputs(const OutputVector& new_args) const override;
};
} // namespace dynamic
} // namespace op
NGRAPH_API