Skip to content

Commit

Permalink
Merge pull request opencv#18671 from rgarnov:rg/rmat_and_s11n_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Oct 28, 2020
2 parents f345ed5 + afbf383 commit 209f6cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/gapi/src/api/gmat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool GMatDesc::canDescribe(const cv::Mat& mat) const

bool GMatDesc::canDescribe(const cv::RMat& mat) const
{
return *this == mat.desc();
return canDescribeHelper(*this, mat);
}

}// namespace cv
2 changes: 1 addition & 1 deletion modules/gapi/src/backends/common/gbackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ inline cv::util::optional<T> getCompileArg(const cv::GCompileArgs &args)
return cv::gapi::getCompileArg<T>(args);
}

void createMat(const cv::GMatDesc& desc, cv::Mat& mat);
void GAPI_EXPORTS createMat(const cv::GMatDesc& desc, cv::Mat& mat);

}} // cv::gimpl

Expand Down
21 changes: 14 additions & 7 deletions modules/gapi/src/backends/common/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,24 @@ void linkNodes(ade::Graph& g) {
}

void relinkProto(ade::Graph& g) {
using namespace cv::gimpl;
// identify which node handles map to the protocol
// input/output object in the reconstructed graph
using S = std::set<cv::gimpl::RcDesc>; // FIXME: use ...
using M = std::map<cv::gimpl::RcDesc, ade::NodeHandle>; // FIXME: unordered!
using S = std::set<RcDesc>; // FIXME: use ...
using M = std::map<RcDesc, ade::NodeHandle>; // FIXME: unordered!

cv::gimpl::GModel::Graph gm(g);
auto &proto = gm.metadata().get<cv::gimpl::Protocol>();
GModel::Graph gm(g);
auto &proto = gm.metadata().get<Protocol>();

const S set_in(proto.inputs.begin(), proto.inputs.end());
const S set_out(proto.outputs.begin(), proto.outputs.end());
M map_in, map_out;

// Associate the protocol node handles with their resource identifiers
for (auto &&nh : gm.nodes()) {
if (gm.metadata(nh).get<cv::gimpl::NodeType>().t == cv::gimpl::NodeType::DATA) {
const auto &d = gm.metadata(nh).get<cv::gimpl::Data>();
const auto rc = cv::gimpl::RcDesc{d.rc, d.shape, d.ctor};
if (gm.metadata(nh).get<NodeType>().t == NodeType::DATA) {
const auto &d = gm.metadata(nh).get<Data>();
const auto rc = RcDesc{d.rc, d.shape, d.ctor};
if (set_in.count(rc) > 0) {
GAPI_DbgAssert(set_out.count(rc) == 0);
map_in[rc] = nh;
Expand All @@ -128,6 +129,12 @@ void relinkProto(ade::Graph& g) {
proto.out_nhs.clear();
for (auto &rc : proto.inputs) { proto.in_nhs .push_back(map_in .at(rc)); }
for (auto &rc : proto.outputs) { proto.out_nhs.push_back(map_out.at(rc)); }

// If a subgraph is being serialized it's possible that
// some of its in/out nodes are INTERNAL in the full graph.
// Set their storage apporpriately
for (auto &nh : proto.in_nhs) { gm.metadata(nh).get<Data>().storage = Data::Storage::INPUT; }
for (auto &nh : proto.out_nhs) { gm.metadata(nh).get<Data>().storage = Data::Storage::OUTPUT; }
}

} // anonymous namespace
Expand Down

0 comments on commit 209f6cd

Please sign in to comment.