1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #25662 from ujjayant-kadian:uk/port-gapi-onnxrt-backend-into-v2-api

Port G-API ONNXRT backend into V2 API #25662

### Pull Request Readiness Checklist

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

- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] 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
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Ujjayant Kadian
2024-05-31 15:01:46 +01:00
committed by GitHub
parent d7f04a9d33
commit dcce2b8b24
2 changed files with 48 additions and 9 deletions
@@ -178,16 +178,26 @@ static void addTensorRTExecutionProvider(Ort::SessionOptions *session_options,
static void addOpenVINOExecutionProvider(Ort::SessionOptions *session_options,
const cv::gapi::onnx::ep::OpenVINO &ov_ep) {
OrtOpenVINOProviderOptions options{};
options.device_type = ov_ep.device_type.c_str();
options.cache_dir = ov_ep.cache_dir.c_str();
options.num_of_threads = ov_ep.num_of_threads;
options.enable_opencl_throttling = ov_ep.enable_opencl_throttling;
options.enable_dynamic_shapes = ov_ep.enable_dynamic_shapes;
options.context = nullptr;
std::unordered_map<std::string, std::string> options;
try {
session_options->AppendExecutionProvider_OpenVINO(options);
// If the OpenVINO Execution Provider object was initialized with a parameters map,
// those parameters are used directly.
// Otherwise, the function constructs the options map from the individual member
// variables of the OpenVINO object.
if (ov_ep.params_map.empty()) {
options = {
{"device_type", ov_ep.device_type},
{"cache_dir", ov_ep.cache_dir},
{"num_of_threads", ov_ep.num_of_threads > 0 ? std::to_string(ov_ep.num_of_threads) : ""},
{"enable_opencl_throttling", ov_ep.enable_opencl_throttling ? "True" : "False"},
{"enable_dynamic_shapes", ov_ep.enable_dynamic_shapes ? "True" : "False"},
};
} else {
options.insert(ov_ep.params_map.begin(), ov_ep.params_map.end());
}
// AppendExecutionProvider function expects a const std::unordered_map as its second argument
session_options->AppendExecutionProvider("OpenVINO", options);
} catch (const std::exception &e) {
std::stringstream ss;
ss << "ONNX Backend: Failed to enable OpenVINO"