1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #24069 from dkurt:openvino_detection_layer

DetectionOutput layer on OpenVINO without limitations #24069

### Pull Request Readiness Checklist

required for https://github.com/opencv/opencv/pull/23987

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Dmitry Kurtaev
2023-08-02 14:28:47 +03:00
committed by GitHub
parent f46f7eff0c
commit 195aad8e6a
4 changed files with 58 additions and 16 deletions
@@ -221,7 +221,7 @@ public:
{
return backendId == DNN_BACKEND_OPENCV ||
(backendId == DNN_BACKEND_CUDA && !_groupByClasses) ||
(backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && !_locPredTransposed && _bboxesNormalized);
backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH;
}
bool getMemoryShapes(const std::vector<MatShape> &inputs,
@@ -1006,9 +1006,30 @@ public:
virtual Ptr<BackendNode> initNgraph(const std::vector<Ptr<BackendWrapper> >& inputs, const std::vector<Ptr<BackendNode> >& nodes) CV_OVERRIDE
{
CV_Assert(nodes.size() == 3);
auto& box_logits = nodes[0].dynamicCast<InfEngineNgraphNode>()->node;
auto& class_preds = nodes[1].dynamicCast<InfEngineNgraphNode>()->node;
auto& proposals = nodes[2].dynamicCast<InfEngineNgraphNode>()->node;
auto box_logits = nodes[0].dynamicCast<InfEngineNgraphNode>()->node;
auto class_preds = nodes[1].dynamicCast<InfEngineNgraphNode>()->node;
auto proposals = nodes[2].dynamicCast<InfEngineNgraphNode>()->node;
if (_locPredTransposed) {
// Convert box predictions from yxYX to xyXY
box_logits = std::make_shared<ngraph::op::v1::Reshape>(box_logits,
std::make_shared<ngraph::op::Constant>(ngraph::element::i32, ngraph::Shape{3}, std::vector<int32_t>{0, -1, 2}),
true
);
int axis = 2;
box_logits = std::make_shared<ngraph::op::v1::Reverse>(box_logits,
std::make_shared<ngraph::op::Constant>(ngraph::element::i32, ngraph::Shape{1}, &axis),
ngraph::op::v1::Reverse::Mode::INDEX
);
}
auto shape = std::make_shared<ngraph::op::Constant>(ngraph::element::i32, ngraph::Shape{2}, std::vector<int32_t>{0, -1});
box_logits = std::make_shared<ngraph::op::v1::Reshape>(box_logits, shape, true);
class_preds = std::make_shared<ngraph::op::v1::Reshape>(class_preds, shape, true);
proposals = std::make_shared<ngraph::op::v1::Reshape>(proposals,
std::make_shared<ngraph::op::Constant>(ngraph::element::i32, ngraph::Shape{3}, std::vector<int32_t>{0, _varianceEncodedInTarget ? 1 : 2, -1}),
true
);
ngraph::op::DetectionOutputAttrs attrs;
attrs.num_classes = _numClasses;