Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class GAPI_EXPORTS_W_SIMPLE PyParams {
GAPI_WRAP
PyParams& cfgDisableMemPattern();

GAPI_WRAP
PyParams& cfgSessionOptions(const std::map<std::string, std::string>& options);

GBackend backend() const;
std::string tag() const;
cv::util::any params() const;
Expand Down
21 changes: 20 additions & 1 deletion modules/gapi/include/opencv2/gapi/infer/onnx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ struct ParamDesc {
std::unordered_map<std::string, std::pair<cv::Scalar, cv::Scalar> > generic_mstd;
std::unordered_map<std::string, bool> generic_norm;

std::map<std::string, std::string> session_options;
std::vector<cv::gapi::onnx::ep::EP> execution_providers;
bool disable_mem_pattern;
};
Expand Down Expand Up @@ -634,6 +635,19 @@ template<typename Net> class Params {
return *this;
}

/** @brief Configures session options for ONNX Runtime.

This function is used to set various session options for the ONNX Runtime
session by accepting a map of key-value pairs.

@param options A map of session option to be applied to the ONNX Runtime session.
@return the reference on modified object.
*/
Params<Net>& cfgSessionOptions(const std::map<std::string, std::string>& options) {
desc.session_options.insert(options.begin(), options.end());
return *this;
}

// BEGIN(G-API's network parametrization API)
GBackend backend() const { return cv::gapi::onnx::backend(); }
std::string tag() const { return Net::tag(); }
Expand Down Expand Up @@ -661,7 +675,7 @@ class Params<cv::gapi::Generic> {
@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) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚋🚋🚋


/** @see onnx::Params::cfgMeanStdDev. */
void cfgMeanStdDev(const std::string &layer,
Expand Down Expand Up @@ -705,6 +719,11 @@ class Params<cv::gapi::Generic> {
desc.disable_mem_pattern = true;
}

/** @see onnx::Params::cfgSessionOptions. */
void cfgSessionOptions(const std::map<std::string, std::string>& options) {
desc.session_options.insert(options.begin(), options.end());
}

// BEGIN(G-API's network parametrization API)
GBackend backend() const { return cv::gapi::onnx::backend(); }
std::string tag() const { return m_tag; }
Expand Down
6 changes: 6 additions & 0 deletions modules/gapi/src/backends/onnx/bindings_onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ cv::gapi::onnx::PyParams::cfgDisableMemPattern() {
return *this;
}

cv::gapi::onnx::PyParams&
cv::gapi::onnx::PyParams::cfgSessionOptions(const std::map<std::string, std::string>& options) {
m_priv->cfgSessionOptions(options);
return *this;
}

cv::gapi::GBackend cv::gapi::onnx::PyParams::backend() const {
return m_priv->backend();
}
Expand Down
4 changes: 4 additions & 0 deletions modules/gapi/src/backends/onnx/gonnxbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ ONNXCompiled::ONNXCompiled(const gapi::onnx::detail::ParamDesc &pp)
cv::gimpl::onnx::addExecutionProvider(&session_options, ep);
}

for (const auto &option : pp.session_options) {
session_options.AddConfigEntry(option.first.c_str(), option.second.c_str());
}

if (pp.disable_mem_pattern) {
session_options.DisableMemPattern();
}
Expand Down