|
15 | 15 |
|
16 | 16 | #include <opencv2/gapi/opencv_includes.hpp>
|
17 | 17 | #include <opencv2/gapi/util/any.hpp>
|
| 18 | +#include <opencv2/gapi/util/optional.hpp> |
18 | 19 |
|
19 | 20 | #include <opencv2/core/cvdef.h> // GAPI_EXPORTS
|
20 | 21 | #include <opencv2/gapi/gkernel.hpp> // GKernelPackage
|
@@ -354,6 +355,7 @@ struct ParamDesc {
|
354 | 355 | std::map<std::string, std::string> session_options;
|
355 | 356 | std::vector<cv::gapi::onnx::ep::EP> execution_providers;
|
356 | 357 | bool disable_mem_pattern;
|
| 358 | + cv::util::optional<int> opt_level; |
357 | 359 | };
|
358 | 360 | } // namespace detail
|
359 | 361 |
|
@@ -648,6 +650,17 @@ template<typename Net> class Params {
|
648 | 650 | return *this;
|
649 | 651 | }
|
650 | 652 |
|
| 653 | + /** @brief Configures optimization level for ONNX Runtime. |
| 654 | +
|
| 655 | + @param opt_level [optimization level]: Valid values are 0 (disable), 1 (basic), 2 (extended), 99 (all). |
| 656 | + Please see onnxruntime_c_api.h (enum GraphOptimizationLevel) for the full list of all optimization levels. |
| 657 | + @return the reference on modified object. |
| 658 | + */ |
| 659 | + Params<Net>& cfgOptLevel(const int opt_level) { |
| 660 | + desc.opt_level = cv::util::make_optional(opt_level); |
| 661 | + return *this; |
| 662 | + } |
| 663 | + |
651 | 664 | // BEGIN(G-API's network parametrization API)
|
652 | 665 | GBackend backend() const { return cv::gapi::onnx::backend(); }
|
653 | 666 | std::string tag() const { return Net::tag(); }
|
@@ -675,7 +688,7 @@ class Params<cv::gapi::Generic> {
|
675 | 688 | @param model_path path to model file (.onnx file).
|
676 | 689 | */
|
677 | 690 | Params(const std::string& tag, const std::string& model_path)
|
678 |
| - : desc{model_path, 0u, 0u, {}, {}, {}, {}, {}, {}, {}, {}, {}, true, {}, {}, {}, {}, false}, m_tag(tag) {} |
| 691 | + : desc{ model_path, 0u, 0u, {}, {}, {}, {}, {}, {}, {}, {}, {}, true, {}, {}, {}, {}, false, {} }, m_tag(tag) {} |
679 | 692 |
|
680 | 693 | /** @see onnx::Params::cfgMeanStdDev. */
|
681 | 694 | void cfgMeanStdDev(const std::string &layer,
|
@@ -724,6 +737,11 @@ class Params<cv::gapi::Generic> {
|
724 | 737 | desc.session_options.insert(options.begin(), options.end());
|
725 | 738 | }
|
726 | 739 |
|
| 740 | +/** @see onnx::Params::cfgOptLevel. */ |
| 741 | + void cfgOptLevel(const int opt_level) { |
| 742 | + desc.opt_level = cv::util::make_optional(opt_level); |
| 743 | + } |
| 744 | + |
727 | 745 | // BEGIN(G-API's network parametrization API)
|
728 | 746 | GBackend backend() const { return cv::gapi::onnx::backend(); }
|
729 | 747 | std::string tag() const { return m_tag; }
|
|
0 commit comments