1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #18491 from TolyaTalamanov:at/wrap-inference

[G-API] Wrap cv::gapi::infer<Generic> into python

* Introduce generic infer

* Move Generic to infer.hpp

* Removew num_outs

* Fix windows warnings

* Fix comments to review

* Fix doxygen

* Add comment

* Fix comments to review

* Wrap inference to python

* Add default ctor to Params

* Add test

* Fix clang build

* Implement GInferInputs/GInferOutputs as Pimpl

* Add checkIEtarget to infer test

* Fix path

* Supress warning

* Use getAvailableDevices insted of checkIETarget

* Move PyParams to bindings_ie

* Add namespace

* Update CMakeLists.txt
This commit is contained in:
Anatoliy Talamanov
2020-10-26 22:02:03 +03:00
committed by GitHub
parent 36598677cf
commit 93c3775927
9 changed files with 224 additions and 28 deletions
+36 -13
View File
@@ -29,29 +29,52 @@ std::vector<cv::gapi::GBackend> cv::gapi::GNetPackage::backends() const {
// FIXME: Inference API is currently only available in full mode
#if !defined(GAPI_STANDALONE)
cv::GMat& cv::GInferInputs::operator[](const std::string& name) {
return in_blobs[name];
cv::GInferInputs::GInferInputs()
: in_blobs(std::make_shared<Map>())
{
}
const std::unordered_map<std::string, cv::GMat>& cv::GInferInputs::getBlobs() const {
return in_blobs;
cv::GMat& cv::GInferInputs::operator[](const std::string& name) {
return (*in_blobs)[name];
}
const cv::GInferInputs::Map& cv::GInferInputs::getBlobs() const {
return *in_blobs;
}
void cv::GInferInputs::setInput(const std::string& name, const cv::GMat& value) {
in_blobs->emplace(name, value);
}
struct cv::GInferOutputs::Priv
{
Priv(std::shared_ptr<cv::GCall>);
std::shared_ptr<cv::GCall> call;
InOutInfo* info = nullptr;
std::unordered_map<std::string, cv::GMat> out_blobs;
};
cv::GInferOutputs::Priv::Priv(std::shared_ptr<cv::GCall> c)
: call(std::move(c)), info(cv::util::any_cast<InOutInfo>(&call->params()))
{
}
cv::GInferOutputs::GInferOutputs(std::shared_ptr<cv::GCall> call)
: m_call(std::move(call)), m_info(cv::util::any_cast<InOutInfo>(&m_call->params()))
: m_priv(std::make_shared<cv::GInferOutputs::Priv>(std::move(call)))
{
};
}
cv::GMat cv::GInferOutputs::at(const std::string& name)
{
auto it = out_blobs.find(name);
if (it == out_blobs.end()) {
auto it = m_priv->out_blobs.find(name);
if (it == m_priv->out_blobs.end()) {
// FIXME: Avoid modifying GKernel
m_call->kernel().outShapes.push_back(cv::GShape::GMAT);
int out_idx = static_cast<int>(out_blobs.size());
it = out_blobs.emplace(name, m_call->yield(out_idx)).first;
m_info->out_names.push_back(name);
m_priv->call->kernel().outShapes.push_back(cv::GShape::GMAT);
int out_idx = static_cast<int>(m_priv->out_blobs.size());
it = m_priv->out_blobs.emplace(name, m_priv->call->yield(out_idx)).first;
m_priv->info->out_names.push_back(name);
}
return it->second;
};
}
#endif // GAPI_STANDALONE
@@ -0,0 +1,39 @@
#include <opencv2/gapi/infer/bindings_ie.hpp>
cv::gapi::ie::PyParams::PyParams(const std::string &tag,
const std::string &model,
const std::string &weights,
const std::string &device)
: m_priv(std::make_shared<Params<cv::gapi::Generic>>(tag, model, weights, device)) {
}
cv::gapi::ie::PyParams::PyParams(const std::string &tag,
const std::string &model,
const std::string &device)
: m_priv(std::make_shared<Params<cv::gapi::Generic>>(tag, model, device)) {
}
cv::gapi::GBackend cv::gapi::ie::PyParams::backend() const {
return m_priv->backend();
}
std::string cv::gapi::ie::PyParams::tag() const {
return m_priv->tag();
}
cv::util::any cv::gapi::ie::PyParams::params() const {
return m_priv->params();
}
cv::gapi::ie::PyParams cv::gapi::ie::params(const std::string &tag,
const std::string &model,
const std::string &weights,
const std::string &device) {
return {tag, model, weights, device};
}
cv::gapi::ie::PyParams cv::gapi::ie::params(const std::string &tag,
const std::string &model,
const std::string &device) {
return {tag, model, device};
}