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
@@ -54,6 +54,9 @@ public:
GAPI_WRAP
PyParams& cfgSessionOptions(const std::map<std::string, std::string>& options);
GAPI_WRAP
PyParams& cfgOptLevel(const int opt_level);
GBackend backend() const;
std::string tag() const;
cv::util::any params() const;
@@ -15,6 +15,7 @@
#include <opencv2/gapi/opencv_includes.hpp>
#include <opencv2/gapi/util/any.hpp>
#include <opencv2/gapi/util/optional.hpp>
#include <opencv2/core/cvdef.h> // GAPI_EXPORTS
#include <opencv2/gapi/gkernel.hpp> // GKernelPackage
@@ -354,6 +355,7 @@ struct ParamDesc {
std::map<std::string, std::string> session_options;
std::vector<cv::gapi::onnx::ep::EP> execution_providers;
bool disable_mem_pattern;
cv::util::optional<int> opt_level;
};
} // namespace detail
@@ -648,6 +650,17 @@ public:
return *this;
}
/** @brief Configures optimization level for ONNX Runtime.
@param opt_level [optimization level]: Valid values are 0 (disable), 1 (basic), 2 (extended), 99 (all).
Please see onnxruntime_c_api.h (enum GraphOptimizationLevel) for the full list of all optimization levels.
@return the reference on modified object.
*/
Params<Net>& cfgOptLevel(const int opt_level) {
desc.opt_level = cv::util::make_optional(opt_level);
return *this;
}
// BEGIN(G-API's network parametrization API)
GBackend backend() const { return cv::gapi::onnx::backend(); }
std::string tag() const { return Net::tag(); }
@@ -675,7 +688,7 @@ public:
@param model_path path to model file (.onnx file).
*/
Params(const std::string& tag, const std::string& model_path)
: desc{model_path, 0u, 0u, {}, {}, {}, {}, {}, {}, {}, {}, {}, true, {}, {}, {}, {}, false}, m_tag(tag) {}
: desc{ model_path, 0u, 0u, {}, {}, {}, {}, {}, {}, {}, {}, {}, true, {}, {}, {}, {}, false, {} }, m_tag(tag) {}
/** @see onnx::Params::cfgMeanStdDev. */
void cfgMeanStdDev(const std::string &layer,
@@ -724,6 +737,11 @@ public:
desc.session_options.insert(options.begin(), options.end());
}
/** @see onnx::Params::cfgOptLevel. */
void cfgOptLevel(const int opt_level) {
desc.opt_level = cv::util::make_optional(opt_level);
}
// BEGIN(G-API's network parametrization API)
GBackend backend() const { return cv::gapi::onnx::backend(); }
std::string tag() const { return m_tag; }