mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #18419 from TolyaTalamanov:at/generic-inference
[G-API] Introduce generic version for cv::gapi::infer * 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 * standoalone ifdef in ginfer.cpp * Fix test
This commit is contained in:
committed by
GitHub
parent
6a51e3b39a
commit
76be3529f4
@@ -78,3 +78,13 @@ const cv::GCall::Priv& cv::GCall::priv() const
|
||||
{
|
||||
return *m_priv;
|
||||
}
|
||||
|
||||
cv::GKernel& cv::GCall::kernel()
|
||||
{
|
||||
return m_priv->m_k;
|
||||
}
|
||||
|
||||
cv::util::any& cv::GCall::params()
|
||||
{
|
||||
return m_priv->m_params;
|
||||
}
|
||||
|
||||
@@ -42,10 +42,11 @@ class GCall::Priv
|
||||
{
|
||||
public:
|
||||
std::vector<GArg> m_args;
|
||||
const GKernel m_k;
|
||||
GKernel m_k;
|
||||
|
||||
// TODO: Rename to "constructionNode" or smt to reflect its lifetime
|
||||
GNode m_node;
|
||||
cv::util::any m_params;
|
||||
|
||||
explicit Priv(const GKernel &k);
|
||||
};
|
||||
|
||||
@@ -25,3 +25,33 @@ std::vector<cv::gapi::GBackend> cv::gapi::GNetPackage::backends() const {
|
||||
for (const auto &nn : networks) unique_set.insert(nn.backend);
|
||||
return std::vector<cv::gapi::GBackend>(unique_set.begin(), unique_set.end());
|
||||
}
|
||||
|
||||
// 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];
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, cv::GMat>& cv::GInferInputs::getBlobs() const {
|
||||
return in_blobs;
|
||||
}
|
||||
|
||||
cv::GInferOutputs::GInferOutputs(std::shared_ptr<cv::GCall> call)
|
||||
: m_call(std::move(call)), m_info(cv::util::any_cast<InOutInfo>(&m_call->params()))
|
||||
{
|
||||
};
|
||||
|
||||
cv::GMat cv::GInferOutputs::at(const std::string& name)
|
||||
{
|
||||
auto it = out_blobs.find(name);
|
||||
if (it == 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);
|
||||
}
|
||||
return it->second;
|
||||
};
|
||||
#endif // GAPI_STANDALONE
|
||||
|
||||
@@ -721,9 +721,23 @@ namespace {
|
||||
// FIXME: Introduce a DNNBackend interface which'd specify
|
||||
// the framework for this???
|
||||
GIEModel gm(gr);
|
||||
const auto &np = gm.metadata(nh).get<NetworkParams>();
|
||||
const auto &pp = cv::util::any_cast<cv::gapi::ie::detail::ParamDesc>(np.opaque);
|
||||
auto &np = gm.metadata(nh).get<NetworkParams>();
|
||||
auto &pp = cv::util::any_cast<cv::gapi::ie::detail::ParamDesc>(np.opaque);
|
||||
const auto &ki = cv::util::any_cast<KImpl>(ii.opaque);
|
||||
|
||||
GModel::Graph model(gr);
|
||||
auto& op = model.metadata(nh).get<Op>();
|
||||
|
||||
// NB: In case generic infer, info about in/out names is stored in operation (op.params)
|
||||
if (pp.is_generic)
|
||||
{
|
||||
auto& info = cv::util::any_cast<cv::InOutInfo>(op.params);
|
||||
pp.input_names = info.in_names;
|
||||
pp.output_names = info.out_names;
|
||||
pp.num_in = info.in_names.size();
|
||||
pp.num_out = info.out_names.size();
|
||||
}
|
||||
|
||||
gm.metadata(nh).set(IEUnit{pp});
|
||||
gm.metadata(nh).set(IECallable{ki.run});
|
||||
gm.metadata(nh).set(CustomMetaFunction{ki.customMetaFunc});
|
||||
|
||||
@@ -23,12 +23,16 @@
|
||||
|
||||
namespace cv { namespace gimpl {
|
||||
|
||||
ade::NodeHandle GModel::mkOpNode(GModel::Graph &g, const GKernel &k, const std::vector<GArg> &args, const std::string &island)
|
||||
ade::NodeHandle GModel::mkOpNode(GModel::Graph &g,
|
||||
const GKernel &k,
|
||||
const std::vector<GArg> &args,
|
||||
const cv::util::any ¶ms,
|
||||
const std::string &island)
|
||||
{
|
||||
ade::NodeHandle op_h = g.createNode();
|
||||
g.metadata(op_h).set(NodeType{NodeType::OP});
|
||||
//These extra empty {} are to please GCC (-Wmissing-field-initializers)
|
||||
g.metadata(op_h).set(Op{k, args, {}, {}});
|
||||
g.metadata(op_h).set(Op{k, args, {}, {}, params});
|
||||
if (!island.empty())
|
||||
g.metadata(op_h).set(Island{island});
|
||||
return op_h;
|
||||
|
||||
@@ -61,6 +61,7 @@ struct Op
|
||||
std::vector<RcDesc> outs; // TODO: Introduce a new type for resource references
|
||||
|
||||
cv::gapi::GBackend backend;
|
||||
cv::util::any params; // Operation specific information
|
||||
};
|
||||
|
||||
struct Data
|
||||
@@ -262,7 +263,11 @@ namespace GModel
|
||||
// GAPI_EXPORTS for tests
|
||||
GAPI_EXPORTS void init (Graph& g);
|
||||
|
||||
GAPI_EXPORTS ade::NodeHandle mkOpNode(Graph &g, const GKernel &k, const std::vector<GArg>& args, const std::string &island);
|
||||
GAPI_EXPORTS ade::NodeHandle mkOpNode(Graph &g,
|
||||
const GKernel &k,
|
||||
const std::vector<GArg>& args,
|
||||
const cv::util::any& params,
|
||||
const std::string &island);
|
||||
// Isn't used by the framework or default backends, required for external backend development
|
||||
GAPI_EXPORTS ade::NodeHandle mkDataNode(Graph &g, const GShape shape);
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ ade::NodeHandle cv::gimpl::GModelBuilder::put_OpNode(const cv::GNode &node)
|
||||
{
|
||||
GAPI_Assert(node.shape() == GNode::NodeShape::CALL);
|
||||
const auto &call_p = node.call().priv();
|
||||
auto nh = cv::gimpl::GModel::mkOpNode(m_gm, call_p.m_k, call_p.m_args, node_p.m_island);
|
||||
auto nh = cv::gimpl::GModel::mkOpNode(m_gm, call_p.m_k, call_p.m_args, call_p.m_params, node_p.m_island);
|
||||
m_graph_ops[&node_p] = nh;
|
||||
return nh;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user