1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43: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
+19 -10
View File
@@ -133,14 +133,18 @@ struct InOutInfo
* @{
* @brief G-API object used to collect network inputs
*/
class GAPI_EXPORTS GInferInputs
class GAPI_EXPORTS_W_SIMPLE GInferInputs
{
using Map = std::unordered_map<std::string, GMat>;
public:
GAPI_WRAP GInferInputs();
GAPI_WRAP void setInput(const std::string& name, const cv::GMat& value);
cv::GMat& operator[](const std::string& name);
const std::unordered_map<std::string, cv::GMat>& getBlobs() const;
const Map& getBlobs() const;
private:
std::unordered_map<std::string, cv::GMat> in_blobs;
std::shared_ptr<Map> in_blobs;
};
/** @} */
@@ -148,16 +152,16 @@ private:
* @{
* @brief G-API object used to collect network outputs
*/
struct GAPI_EXPORTS GInferOutputs
struct GAPI_EXPORTS_W_SIMPLE GInferOutputs
{
public:
GAPI_WRAP GInferOutputs() = default;
GInferOutputs(std::shared_ptr<cv::GCall> call);
cv::GMat at(const std::string& name);
GAPI_WRAP cv::GMat at(const std::string& name);
private:
std::shared_ptr<cv::GCall> m_call;
InOutInfo* m_info = nullptr;
std::unordered_map<std::string, cv::GMat> out_blobs;
struct Priv;
std::shared_ptr<Priv> m_priv;
};
/** @} */
@@ -333,6 +337,11 @@ infer(const std::string& tag, const GInferInputs& inputs)
return GInferOutputs{std::move(call)};
}
GAPI_EXPORTS_W inline GInferOutputs infer(const String& name, const GInferInputs& inputs)
{
return infer<Generic>(name, inputs);
}
} // namespace gapi
} // namespace cv
@@ -361,8 +370,8 @@ struct GAPI_EXPORTS GNetParam {
*
* @sa cv::gapi::networks
*/
struct GAPI_EXPORTS GNetPackage {
GNetPackage() : GNetPackage({}) {}
struct GAPI_EXPORTS_W_SIMPLE GNetPackage {
GAPI_WRAP GNetPackage() : GNetPackage({}) {}
explicit GNetPackage(std::initializer_list<GNetParam> &&ii);
std::vector<GBackend> backends() const;
std::vector<GNetParam> networks;
@@ -0,0 +1,56 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2020 Intel Corporation
#ifndef OPENCV_GAPI_INFER_BINDINGS_IE_HPP
#define OPENCV_GAPI_INFER_BINDINGS_IE_HPP
#include <opencv2/gapi/util/any.hpp>
#include "opencv2/gapi/own/exports.hpp" // GAPI_EXPORTS
#include <opencv2/gapi/gkernel.hpp> // GKernelPackage
#include <opencv2/gapi/infer/ie.hpp> // Params
#include <string>
namespace cv {
namespace gapi {
namespace ie {
// NB: Used by python wrapper
// This class can be marked as SIMPLE, because it's implemented as pimpl
class GAPI_EXPORTS_W_SIMPLE PyParams {
public:
PyParams() = default;
PyParams(const std::string &tag,
const std::string &model,
const std::string &weights,
const std::string &device);
PyParams(const std::string &tag,
const std::string &model,
const std::string &device);
GBackend backend() const;
std::string tag() const;
cv::util::any params() const;
private:
std::shared_ptr<Params<cv::gapi::Generic>> m_priv;
};
GAPI_EXPORTS_W PyParams params(const std::string &tag,
const std::string &model,
const std::string &weights,
const std::string &device);
GAPI_EXPORTS_W PyParams params(const std::string &tag,
const std::string &model,
const std::string &device);
} // namespace ie
} // namespace gapi
} // namespace cv
#endif // OPENCV_GAPI_INFER_BINDINGS_IE_HPP
@@ -162,4 +162,4 @@ protected:
} // namespace gapi
} // namespace cv
#endif // OPENCV_GAPI_INFER_HPP
#endif // OPENCV_GAPI_INFER_IE_HPP