1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #26293 from SeptimiuIoachimNeagaIntel:EISW-140103_optimization_flag

G-API: Introduce level optimization flag for ONNXRT backend #26293

### Pull Request Readiness Checklist

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
- [ ] 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:
Septimiu Neaga
2024-10-17 10:22:08 +03:00
committed by GitHub
parent 489df18a13
commit 3919f33e21
4 changed files with 52 additions and 1 deletions
@@ -63,6 +63,12 @@ cv::gapi::onnx::PyParams::cfgSessionOptions(const std::map<std::string, std::str
return *this;
}
cv::gapi::onnx::PyParams&
cv::gapi::onnx::PyParams::cfgOptLevel(const int opt_level) {
m_priv->cfgOptLevel(opt_level);
return *this;
}
cv::gapi::GBackend cv::gapi::onnx::PyParams::backend() const {
return m_priv->backend();
}
@@ -701,6 +701,26 @@ namespace cv {
namespace gimpl {
namespace onnx {
static GraphOptimizationLevel convertToGraphOptimizationLevel(const int opt_level) {
switch (opt_level) {
case ORT_DISABLE_ALL:
return ORT_DISABLE_ALL;
case ORT_ENABLE_BASIC:
return ORT_ENABLE_BASIC;
case ORT_ENABLE_EXTENDED:
return ORT_ENABLE_EXTENDED;
case ORT_ENABLE_ALL:
return ORT_ENABLE_ALL;
default:
if (opt_level > ORT_ENABLE_ALL) { // relax constraint
return ORT_ENABLE_ALL;
}
else {
cv::util::throw_error(std::invalid_argument("Invalid argument opt_level = " + std::to_string(opt_level)));
}
}
}
ONNXCompiled::ONNXCompiled(const gapi::onnx::detail::ParamDesc &pp)
: params(pp) {
// Validate input parameters before allocating any resources
@@ -726,6 +746,10 @@ ONNXCompiled::ONNXCompiled(const gapi::onnx::detail::ParamDesc &pp)
if (pp.disable_mem_pattern) {
session_options.DisableMemPattern();
}
if (pp.opt_level.has_value()) {
session_options.SetGraphOptimizationLevel(convertToGraphOptimizationLevel(pp.opt_level.value()));
}
this_env = Ort::Env(ORT_LOGGING_LEVEL_WARNING, "");
#ifndef _WIN32
this_session = Ort::Session(this_env, params.model_path.data(), session_options);