mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 09:25:45 +08:00
Merge pull request #25791 from ujjayant-kadian:uk/extend-gapi-onnx-params-arbitrary-session-options
Extending G-API onnx::Params to pass arbitrary session options #25791 ### 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:
parent
7ef42d7706
commit
5dc1b39e4c
@ -51,6 +51,9 @@ public:
|
|||||||
GAPI_WRAP
|
GAPI_WRAP
|
||||||
PyParams& cfgDisableMemPattern();
|
PyParams& cfgDisableMemPattern();
|
||||||
|
|
||||||
|
GAPI_WRAP
|
||||||
|
PyParams& cfgSessionOptions(const std::map<std::string, std::string>& options);
|
||||||
|
|
||||||
GBackend backend() const;
|
GBackend backend() const;
|
||||||
std::string tag() const;
|
std::string tag() const;
|
||||||
cv::util::any params() const;
|
cv::util::any params() const;
|
||||||
|
@ -351,6 +351,7 @@ struct ParamDesc {
|
|||||||
std::unordered_map<std::string, std::pair<cv::Scalar, cv::Scalar> > generic_mstd;
|
std::unordered_map<std::string, std::pair<cv::Scalar, cv::Scalar> > generic_mstd;
|
||||||
std::unordered_map<std::string, bool> generic_norm;
|
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;
|
std::vector<cv::gapi::onnx::ep::EP> execution_providers;
|
||||||
bool disable_mem_pattern;
|
bool disable_mem_pattern;
|
||||||
};
|
};
|
||||||
@ -634,6 +635,19 @@ public:
|
|||||||
return *this;
|
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)
|
// BEGIN(G-API's network parametrization API)
|
||||||
GBackend backend() const { return cv::gapi::onnx::backend(); }
|
GBackend backend() const { return cv::gapi::onnx::backend(); }
|
||||||
std::string tag() const { return Net::tag(); }
|
std::string tag() const { return Net::tag(); }
|
||||||
@ -661,7 +675,7 @@ public:
|
|||||||
@param model_path path to model file (.onnx file).
|
@param model_path path to model file (.onnx file).
|
||||||
*/
|
*/
|
||||||
Params(const std::string& tag, const std::string& model_path)
|
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. */
|
/** @see onnx::Params::cfgMeanStdDev. */
|
||||||
void cfgMeanStdDev(const std::string &layer,
|
void cfgMeanStdDev(const std::string &layer,
|
||||||
@ -705,6 +719,11 @@ public:
|
|||||||
desc.disable_mem_pattern = true;
|
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)
|
// BEGIN(G-API's network parametrization API)
|
||||||
GBackend backend() const { return cv::gapi::onnx::backend(); }
|
GBackend backend() const { return cv::gapi::onnx::backend(); }
|
||||||
std::string tag() const { return m_tag; }
|
std::string tag() const { return m_tag; }
|
||||||
|
@ -57,6 +57,12 @@ cv::gapi::onnx::PyParams::cfgDisableMemPattern() {
|
|||||||
return *this;
|
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 {
|
cv::gapi::GBackend cv::gapi::onnx::PyParams::backend() const {
|
||||||
return m_priv->backend();
|
return m_priv->backend();
|
||||||
}
|
}
|
||||||
|
@ -702,6 +702,10 @@ ONNXCompiled::ONNXCompiled(const gapi::onnx::detail::ParamDesc &pp)
|
|||||||
cv::gimpl::onnx::addExecutionProvider(&session_options, ep);
|
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) {
|
if (pp.disable_mem_pattern) {
|
||||||
session_options.DisableMemPattern();
|
session_options.DisableMemPattern();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user