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

Merge pull request #23595 from TolyaTalamanov:at/implement-openvino-backend

[G-API] Implement OpenVINO 2.0 backend #23595

### Pull Request Readiness Checklist

Implemented basic functionality for `OpenVINO` 2.0 G-API backend.

#### Overview
- [x] Implement `Infer` kernel with some of essential configurable parameters + IR/Blob models format support.
- [ ] Implement the rest of kernels: `InferList`, `InferROI`, `Infer2` + other configurable params (e.g reshape)
- [x] Asyncrhonous execution support
- [ ] Remote context support

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
- [ ] 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:
Anatoliy Talamanov
2023-06-02 13:31:03 +02:00
committed by GitHub
parent 36d6ca529d
commit 5330112f05
15 changed files with 2933 additions and 4 deletions
@@ -227,6 +227,12 @@ inline void convertInt64ToInt32(const int64_t* src, int* dst, size_t size)
[](int64_t el) { return static_cast<int>(el); });
}
inline void convertInt32ToInt64(const int* src, int64_t* dst, size_t size)
{
std::transform(src, src + size, dst,
[](int el) { return static_cast<int64_t>(el); });
}
}} // cv::gimpl
#endif // OPENCV_GAPI_GBACKEND_HPP
@@ -0,0 +1,168 @@
#include <opencv2/gapi/infer/bindings_ov.hpp>
cv::gapi::ov::PyParams::PyParams(const std::string &tag,
const std::string &model_path,
const std::string &bin_path,
const std::string &device)
: m_priv(std::make_shared<Params<cv::gapi::Generic>>(tag, model_path, bin_path, device)) {
}
cv::gapi::ov::PyParams::PyParams(const std::string &tag,
const std::string &blob_path,
const std::string &device)
: m_priv(std::make_shared<Params<cv::gapi::Generic>>(tag, blob_path, device)) {
}
cv::gapi::GBackend cv::gapi::ov::PyParams::backend() const {
return m_priv->backend();
}
std::string cv::gapi::ov::PyParams::tag() const {
return m_priv->tag();
}
cv::util::any cv::gapi::ov::PyParams::params() const {
return m_priv->params();
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgPluginConfig(
const std::map<std::string, std::string> &config) {
m_priv->cfgPluginConfig(config);
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgInputTensorLayout(std::string tensor_layout) {
m_priv->cfgInputTensorLayout(std::move(tensor_layout));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgInputTensorLayout(
std::map<std::string, std::string> layout_map) {
m_priv->cfgInputTensorLayout(std::move(layout_map));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgInputModelLayout(std::string tensor_layout) {
m_priv->cfgInputModelLayout(std::move(tensor_layout));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgInputModelLayout(
std::map<std::string, std::string> layout_map) {
m_priv->cfgInputModelLayout(std::move(layout_map));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgOutputTensorLayout(std::string tensor_layout) {
m_priv->cfgOutputTensorLayout(std::move(tensor_layout));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgOutputTensorLayout(
std::map<std::string, std::string> layout_map) {
m_priv->cfgOutputTensorLayout(std::move(layout_map));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgOutputModelLayout(std::string tensor_layout) {
m_priv->cfgOutputModelLayout(std::move(tensor_layout));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgOutputModelLayout(
std::map<std::string, std::string> layout_map) {
m_priv->cfgOutputModelLayout(std::move(layout_map));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgOutputTensorPrecision(int precision) {
m_priv->cfgOutputTensorPrecision(precision);
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgOutputTensorPrecision(
std::map<std::string, int> precision_map) {
m_priv->cfgOutputTensorPrecision(precision_map);
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgReshape(std::vector<size_t> new_shape) {
m_priv->cfgReshape(std::move(new_shape));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgReshape(
std::map<std::string, std::vector<size_t>> new_shape_map) {
m_priv->cfgReshape(std::move(new_shape_map));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgNumRequests(const size_t nireq) {
m_priv->cfgNumRequests(nireq);
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgMean(std::vector<float> mean_values) {
m_priv->cfgMean(std::move(mean_values));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgMean(
std::map<std::string, std::vector<float>> mean_map) {
m_priv->cfgMean(std::move(mean_map));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgScale(std::vector<float> scale_values) {
m_priv->cfgScale(std::move(scale_values));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgScale(
std::map<std::string, std::vector<float>> scale_map) {
m_priv->cfgScale(std::move(scale_map));
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgResize(int interpolation) {
m_priv->cfgResize(interpolation);
return *this;
}
cv::gapi::ov::PyParams&
cv::gapi::ov::PyParams::cfgResize(std::map<std::string, int> interpolation) {
m_priv->cfgResize(std::move(interpolation));
return *this;
}
cv::gapi::ov::PyParams cv::gapi::ov::params(const std::string &tag,
const std::string &model_path,
const std::string &weights,
const std::string &device) {
return {tag, model_path, weights, device};
}
cv::gapi::ov::PyParams cv::gapi::ov::params(const std::string &tag,
const std::string &blob_path,
const std::string &device) {
return {tag, blob_path, device};
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,66 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2023 Intel Corporation
#ifndef OPENCV_GAPI_GOVBACKEND_HPP
#define OPENCV_GAPI_GOVBACKEND_HPP
// Include anyway - cv::gapi::ov::backend() still needs to be defined
#include "opencv2/gapi/infer/ov.hpp"
#ifdef HAVE_INF_ENGINE
#include <openvino/openvino.hpp>
#include "backends/common/gbackend.hpp"
namespace cv {
namespace gimpl {
namespace ov {
struct OVCompiled {
::ov::CompiledModel compiled_model;
};
class RequestPool;
class GOVExecutable final: public GIslandExecutable
{
const ade::Graph &m_g;
GModel::ConstGraph m_gm;
// The only executable stuff in this graph
// (assuming it is always single-op)
ade::NodeHandle this_nh;
OVCompiled compiled;
// List of all resources in graph (both internal and external)
std::vector<ade::NodeHandle> m_dataNodes;
// To manage multiple async requests
std::unique_ptr<RequestPool> m_reqPool;
public:
GOVExecutable(const ade::Graph &graph,
const std::vector<ade::NodeHandle> &nodes);
virtual inline bool canReshape() const override { return false; }
virtual inline void reshape(ade::Graph&, const GCompileArgs&) override {
GAPI_Error("InternalError"); // Not implemented yet
}
virtual void run(std::vector<InObj> &&,
std::vector<OutObj> &&) override {
GAPI_Error("Not implemented");
}
virtual void run(GIslandExecutable::IInput &in,
GIslandExecutable::IOutput &out) override;
};
}}}
#endif // HAVE_INF_ENGINE
#endif // OPENCV_GAPI_GOVBACKEND_HPP
+35
View File
@@ -0,0 +1,35 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2023 Intel Corporation
#ifndef OPENCV_GAPI_INFER_OV_UTIL_HPP
#define OPENCV_GAPI_INFER_OV_UTIL_HPP
#ifdef HAVE_INF_ENGINE
// NOTE: This file is not included by default in infer/ov.hpp
// and won't be. infer/ov.hpp doesn't depend on OV headers itself.
// This file does -- so needs to be included separately by those who care.
#include <openvino/openvino.hpp>
#include <opencv2/core/cvdef.h> // GAPI_EXPORTS
#include <opencv2/gapi/gkernel.hpp> // GKernelPackage
namespace cv {
namespace gapi {
namespace ov {
namespace util {
// NB: These functions are EXPORTed to make them accessible by the
// test suite only.
GAPI_EXPORTS std::vector<int> to_ocv(const ::ov::Shape &shape);
GAPI_EXPORTS int to_ocv(const ::ov::element::Type &type);
}}}}
#endif // HAVE_INF_ENGINE
#endif // OPENCV_GAPI_INFER_OV_UTIL_HPP