diff --git a/modules/dnn/src/layers/cumsum_layer.cpp b/modules/dnn/src/layers/cumsum_layer.cpp index ae1c825f19..565d09abaa 100644 --- a/modules/dnn/src/layers/cumsum_layer.cpp +++ b/modules/dnn/src/layers/cumsum_layer.cpp @@ -3,6 +3,8 @@ // of this distribution and at http://opencv.org/license.html. #include "../precomp.hpp" +#include "../op_inf_engine.hpp" +#include "../ie_ngraph.hpp" #include "layers_common.hpp" #include @@ -32,6 +34,12 @@ public: return exclusive_raw == 0; } + virtual bool supportBackend(int backendId) CV_OVERRIDE + { + return backendId == DNN_BACKEND_OPENCV || + backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH; + } + void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE { CV_TRACE_FUNCTION(); @@ -120,6 +128,36 @@ public: } } +#ifdef HAVE_DNN_NGRAPH + virtual Ptr initNgraph(const std::vector >& inputs, + const std::vector >& nodes) CV_OVERRIDE + { + std::shared_ptr cumsum; + if (nodes.size() == 2) + { + int32_t axis_shape = 1; + auto axis_scalar = std::make_shared( + nodes[1].dynamicCast()->node, + std::make_shared(ov::element::i32, ov::Shape{}, &axis_shape), + false); + cumsum = std::make_shared( + nodes[0].dynamicCast()->node, + std::make_shared(axis_scalar, ov::element::i32), + exclusive_raw, + reverse_raw); + } + else + { + cumsum = std::make_shared( + nodes[0].dynamicCast()->node, + std::make_shared(ov::element::i32, ov::Shape{}, &axis_raw), + exclusive_raw, + reverse_raw); + } + return Ptr(new InfEngineNgraphNode(cumsum)); + } +#endif // HAVE_DNN_NGRAPH + int axis_raw; int exclusive_raw; int reverse_raw; diff --git a/modules/dnn/src/layers/expand_layer.cpp b/modules/dnn/src/layers/expand_layer.cpp index 752e741a97..09f2d78c4f 100644 --- a/modules/dnn/src/layers/expand_layer.cpp +++ b/modules/dnn/src/layers/expand_layer.cpp @@ -3,6 +3,8 @@ // of this distribution and at http://opencv.org/license.html. #include "../precomp.hpp" +#include "../op_inf_engine.hpp" +#include "../ie_ngraph.hpp" #include namespace cv { namespace dnn { @@ -27,8 +29,10 @@ public: const_input_1d = params.get("const_input_1d", false); } - virtual bool supportBackend(int backendId) CV_OVERRIDE { - return backendId == DNN_BACKEND_OPENCV; + virtual bool supportBackend(int backendId) CV_OVERRIDE + { + return backendId == DNN_BACKEND_OPENCV || + backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH; } virtual bool getMemoryShapes(const std::vector &inputs, @@ -137,6 +141,25 @@ public: } } +#ifdef HAVE_DNN_NGRAPH + virtual Ptr initNgraph(const std::vector >& inputs, + const std::vector >& nodes) CV_OVERRIDE + { + auto input_shape = nodes[0].dynamicCast()->node.get_shape(); + CV_CheckGE(target_shape.size(), input_shape.size(), ""); + + std::vector output_shape(target_shape.begin(), target_shape.end()); + for (int i = 1; i < input_shape.size() + 1; ++i) + output_shape[output_shape.size() - i] = std::max( + (int32_t)input_shape[input_shape.size() - i], + output_shape[output_shape.size() - i]); + + auto shape_node = std::make_shared(ov::element::i32, ov::Shape{output_shape.size()}, output_shape.data()); + auto expand = std::make_shared(nodes[0].dynamicCast()->node, shape_node); + return Ptr(new InfEngineNgraphNode(expand)); + } +#endif // HAVE_DNN_NGRAPH + private: MatShape target_shape; bool const_input_1d; diff --git a/modules/dnn/src/layers/gather_elements_layer.cpp b/modules/dnn/src/layers/gather_elements_layer.cpp index da3ae939df..de15b439a9 100644 --- a/modules/dnn/src/layers/gather_elements_layer.cpp +++ b/modules/dnn/src/layers/gather_elements_layer.cpp @@ -3,6 +3,8 @@ // of this distribution and at http://opencv.org/license.html. #include "../precomp.hpp" +#include "../op_inf_engine.hpp" +#include "../ie_ngraph.hpp" #include namespace cv { namespace dnn { @@ -30,7 +32,8 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { - return backendId == DNN_BACKEND_OPENCV; + return backendId == DNN_BACKEND_OPENCV || + backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH; } virtual bool getMemoryShapes(const std::vector &inputs, @@ -148,6 +151,25 @@ public: }; } +#ifdef HAVE_DNN_NGRAPH + virtual Ptr initNgraph(const std::vector >& inputs, + const std::vector >& nodes) CV_OVERRIDE + { + int32_t indicesBoundValue = nodes[0].dynamicCast()->node.get_shape()[axis]; + auto indicesBound = std::make_shared(ov::element::i32, ov::Shape{}, &indicesBoundValue); + auto indices = std::make_shared(nodes[1].dynamicCast()->node, ov::element::i32); + auto indicesNonNegative = std::make_shared( + std::make_shared(indices, indicesBound), + indicesBound); + + auto gatherElements = std::make_shared( + nodes[0].dynamicCast()->node, + indicesNonNegative, + axis); + return Ptr(new InfEngineNgraphNode(gatherElements)); + } +#endif // HAVE_DNN_NGRAPH + private: int axis; }; diff --git a/modules/dnn/src/layers/gather_layer.cpp b/modules/dnn/src/layers/gather_layer.cpp index 32b76886a3..7b731e6d54 100644 --- a/modules/dnn/src/layers/gather_layer.cpp +++ b/modules/dnn/src/layers/gather_layer.cpp @@ -3,6 +3,8 @@ // of this distribution and at http://opencv.org/license.html. #include "../precomp.hpp" +#include "../op_inf_engine.hpp" +#include "../ie_ngraph.hpp" #include "layers_common.hpp" @@ -20,7 +22,8 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { - return backendId == DNN_BACKEND_OPENCV; + return backendId == DNN_BACKEND_OPENCV || + backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH; } virtual bool getMemoryShapes(const std::vector &inputs, @@ -113,6 +116,19 @@ public: } } +#ifdef HAVE_DNN_NGRAPH + virtual Ptr initNgraph(const std::vector >& inputs, + const std::vector >& nodes) CV_OVERRIDE + { + auto axisNode = std::make_shared(ov::element::i32, ov::Shape{}, &m_axis); + auto gather = std::make_shared( + nodes[0].dynamicCast()->node, + std::make_shared(nodes[1].dynamicCast()->node, ov::element::i32), + axisNode); + return Ptr(new InfEngineNgraphNode(gather)); + } +#endif // HAVE_DNN_NGRAPH + private: // The axis to gather along int m_axis; diff --git a/modules/dnn/src/layers/scatterND_layer.cpp b/modules/dnn/src/layers/scatterND_layer.cpp index 64ddcd0c4f..e64cbfae3e 100644 --- a/modules/dnn/src/layers/scatterND_layer.cpp +++ b/modules/dnn/src/layers/scatterND_layer.cpp @@ -3,6 +3,8 @@ // of this distribution and at http://opencv.org/license.html. #include "../precomp.hpp" +#include "../op_inf_engine.hpp" +#include "../ie_ngraph.hpp" #include "layers_common.hpp" #include // for std::max & std::min @@ -42,7 +44,8 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { - return backendId == DNN_BACKEND_OPENCV; + return backendId == DNN_BACKEND_OPENCV || + (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && reduction == REDUCTION::NONE); } virtual bool getMemoryShapes(const std::vector &inputs, @@ -207,6 +210,18 @@ public: CV_Error(Error::StsBadArg, "Unsupported reduction."); }; } + +#ifdef HAVE_DNN_NGRAPH + virtual Ptr initNgraph(const std::vector >& inputs, + const std::vector >& nodes) CV_OVERRIDE + { + auto scatterND = std::make_shared( + nodes[0].dynamicCast()->node, + std::make_shared(nodes[1].dynamicCast()->node, ov::element::i32), + nodes[2].dynamicCast()->node); + return Ptr(new InfEngineNgraphNode(scatterND)); + } +#endif // HAVE_DNN_NGRAPH }; Ptr ScatterNDLayer::create(const LayerParams& params) diff --git a/modules/dnn/src/layers/scatter_layer.cpp b/modules/dnn/src/layers/scatter_layer.cpp index b4bcdee82e..58d2c2daea 100644 --- a/modules/dnn/src/layers/scatter_layer.cpp +++ b/modules/dnn/src/layers/scatter_layer.cpp @@ -3,6 +3,8 @@ // of this distribution and at http://opencv.org/license.html. #include "../precomp.hpp" +#include "../op_inf_engine.hpp" +#include "../ie_ngraph.hpp" #include "layers_common.hpp" #include // for std::max & std::min @@ -43,7 +45,8 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { - return backendId == DNN_BACKEND_OPENCV; + return backendId == DNN_BACKEND_OPENCV || + (backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH && reduction == REDUCTION::NONE); } virtual bool getMemoryShapes(const std::vector &inputs, @@ -203,6 +206,27 @@ public: }; } +#ifdef HAVE_DNN_NGRAPH + virtual Ptr initNgraph(const std::vector >& inputs, + const std::vector >& nodes) CV_OVERRIDE + { + int32_t indicesBoundValue = nodes[0].dynamicCast()->node.get_shape()[axis]; + auto indicesBound = std::make_shared(ov::element::i32, ov::Shape{}, &indicesBoundValue); + auto indices = std::make_shared(nodes[1].dynamicCast()->node, ov::element::i32); + auto indicesNonNegative = std::make_shared( + std::make_shared(indices, indicesBound), + indicesBound); + + auto axis_node = std::make_shared(ov::element::i32, ov::Shape{}, &axis); + auto scatterElements = std::make_shared( + nodes[0].dynamicCast()->node, + indicesNonNegative, + nodes[2].dynamicCast()->node, + axis_node); + return Ptr(new InfEngineNgraphNode(scatterElements)); + } +#endif // HAVE_DNN_NGRAPH + private: // Attributes int axis; diff --git a/modules/dnn/src/layers/tile_layer.cpp b/modules/dnn/src/layers/tile_layer.cpp index abaf96bd4a..1357b9e89e 100644 --- a/modules/dnn/src/layers/tile_layer.cpp +++ b/modules/dnn/src/layers/tile_layer.cpp @@ -4,6 +4,8 @@ #include "../precomp.hpp" #include "layers_common.hpp" +#include "../op_inf_engine.hpp" +#include "../ie_ngraph.hpp" #include @@ -31,7 +33,8 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { - return backendId == DNN_BACKEND_OPENCV; + return backendId == DNN_BACKEND_OPENCV || + backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH; } virtual bool getMemoryShapes(const std::vector &inputs, @@ -85,6 +88,16 @@ public: tmp.copyTo(out); } +#ifdef HAVE_DNN_NGRAPH + virtual Ptr initNgraph(const std::vector >& inputs, + const std::vector >& nodes) CV_OVERRIDE + { + auto repeats_node = std::make_shared(ov::element::i32, ov::Shape{repeats.size()}, repeats.data()); + auto tile = std::make_shared(nodes[0].dynamicCast()->node, repeats_node); + return Ptr(new InfEngineNgraphNode(tile)); + } +#endif // HAVE_DNN_NGRAPH + private: std::vector repeats; };