mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge branch 4.x
This commit is contained in:
@@ -85,6 +85,19 @@ class GGraphMetaBackendImpl final: public cv::gapi::GBackend::Priv {
|
||||
const std::vector<cv::gimpl::Data>&) const override {
|
||||
return EPtr{new GraphMetaExecutable(graph, nodes)};
|
||||
}
|
||||
|
||||
virtual bool controlsMerge() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool allowsMerge(const cv::gimpl::GIslandModel::Graph &,
|
||||
const ade::NodeHandle &,
|
||||
const ade::NodeHandle &,
|
||||
const ade::NodeHandle &) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
cv::gapi::GBackend graph_meta_backend() {
|
||||
|
||||
@@ -32,6 +32,14 @@ void putData(GSerialized& s, const cv::gimpl::GModel::ConstGraph& cg, const ade:
|
||||
});
|
||||
if (s.m_datas.end() == it) {
|
||||
s.m_datas.push_back(gdata);
|
||||
|
||||
if (cg.metadata(nh).contains<gimpl::ConstValue>()) {
|
||||
size_t datas_num = s.m_datas.size() - 1;
|
||||
GAPI_DbgAssert(datas_num <= static_cast<size_t>(std::numeric_limits<GSerialized::data_tag_t>::max()));
|
||||
GSerialized::data_tag_t tag = static_cast<GSerialized::data_tag_t>(datas_num);
|
||||
s.m_const_datas.emplace(tag,
|
||||
cg.metadata(nh).get<gimpl::ConstValue>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +50,20 @@ void putOp(GSerialized& s, const cv::gimpl::GModel::ConstGraph& cg, const ade::N
|
||||
s.m_ops.push_back(op);
|
||||
}
|
||||
|
||||
void mkDataNode(ade::Graph& g, const cv::gimpl::Data& data) {
|
||||
ade::NodeHandle mkDataNode(ade::Graph& g, const cv::gimpl::Data& data) {
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
auto nh = gm.createNode();
|
||||
gm.metadata(nh).set(cv::gimpl::NodeType{cv::gimpl::NodeType::DATA});
|
||||
gm.metadata(nh).set(data);
|
||||
return nh;
|
||||
}
|
||||
|
||||
ade::NodeHandle mkConstDataNode(ade::Graph& g, const cv::gimpl::Data& data, const cv::gimpl::ConstValue& const_data) {
|
||||
auto nh = mkDataNode(g, data);
|
||||
|
||||
cv::gimpl::GModel::Graph gm(g);
|
||||
gm.metadata(nh).set(const_data);
|
||||
return nh;
|
||||
}
|
||||
|
||||
void mkOpNode(ade::Graph& g, const cv::gimpl::Op& op) {
|
||||
@@ -184,18 +201,20 @@ IOStream& operator<< (IOStream& os, const cv::RMat& mat) {
|
||||
return os;
|
||||
}
|
||||
IIStream& operator>> (IIStream& is, cv::RMat&) {
|
||||
util::throw_error(std::logic_error("operator>> for RMat should never be called"));
|
||||
util::throw_error(std::logic_error("operator>> for RMat should never be called. "
|
||||
"Instead, cv::gapi::deserialize<cv::GRunArgs, AdapterTypes...>() "
|
||||
"should be used"));
|
||||
return is;
|
||||
}
|
||||
|
||||
IOStream& operator<< (IOStream& os, const cv::MediaFrame &) {
|
||||
// Stub
|
||||
GAPI_Assert(false && "cv::MediaFrame serialization is not supported!");
|
||||
IOStream& operator<< (IOStream& os, const cv::MediaFrame &frame) {
|
||||
frame.serialize(os);
|
||||
return os;
|
||||
}
|
||||
IIStream& operator>> (IIStream& is, cv::MediaFrame &) {
|
||||
// Stub
|
||||
GAPI_Assert(false && "cv::MediaFrame serialization is not supported!");
|
||||
util::throw_error(std::logic_error("operator>> for MediaFrame should never be called. "
|
||||
"Instead, cv::gapi::deserialize<cv::GRunArgs, AdapterTypes...>() "
|
||||
"should be used"));
|
||||
return is;
|
||||
}
|
||||
|
||||
@@ -624,6 +643,10 @@ IOStream& operator<< (IOStream& os, const cv::gimpl::Data &d) {
|
||||
return os << d.shape << d.rc << d.meta << d.storage << d.kind;
|
||||
}
|
||||
|
||||
IOStream& operator<< (IOStream& os, const cv::gimpl::ConstValue &cd) {
|
||||
return os << cd.arg;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename Ref, typename T, typename... Ts>
|
||||
@@ -667,6 +690,9 @@ IIStream& operator>> (IIStream& is, cv::gimpl::Data &d) {
|
||||
return is;
|
||||
}
|
||||
|
||||
IIStream& operator>> (IIStream& is, cv::gimpl::ConstValue &cd) {
|
||||
return is >> cd.arg;
|
||||
}
|
||||
|
||||
IOStream& operator<< (IOStream& os, const cv::gimpl::DataObjectCounter &c) {
|
||||
return os << c.m_next_data_id;
|
||||
@@ -709,18 +735,34 @@ void serialize( IOStream& os
|
||||
}
|
||||
s.m_counter = cg.metadata().get<cv::gimpl::DataObjectCounter>();
|
||||
s.m_proto = p;
|
||||
os << s.m_ops << s.m_datas << s.m_counter << s.m_proto;
|
||||
os << s.m_ops << s.m_datas << s.m_counter << s.m_proto << s.m_const_datas;
|
||||
}
|
||||
|
||||
GSerialized deserialize(IIStream &is) {
|
||||
GSerialized s;
|
||||
is >> s.m_ops >> s.m_datas >> s.m_counter >> s.m_proto;
|
||||
is >> s.m_ops >> s.m_datas >> s.m_counter >> s.m_proto >> s.m_const_datas;
|
||||
return s;
|
||||
}
|
||||
|
||||
void reconstruct(const GSerialized &s, ade::Graph &g) {
|
||||
GAPI_Assert(g.nodes().empty());
|
||||
for (const auto& d : s.m_datas) cv::gapi::s11n::mkDataNode(g, d);
|
||||
|
||||
GSerialized::data_tag_t tag = 0;
|
||||
for (const auto& d : s.m_datas) {
|
||||
if (d.storage == gimpl::Data::Storage::CONST_VAL) {
|
||||
auto cit = s.m_const_datas.find(tag);
|
||||
if (cit == s.m_const_datas.end()) {
|
||||
util::throw_error(std::logic_error("Cannot reconstruct graph: Data::Storage::CONST_VAL by tag: " +
|
||||
std::to_string(tag) + " requires ConstValue"));
|
||||
}
|
||||
|
||||
mkConstDataNode(g, d, cit->second);
|
||||
} else {
|
||||
cv::gapi::s11n::mkDataNode(g, d);
|
||||
}
|
||||
|
||||
tag ++;
|
||||
}
|
||||
for (const auto& op : s.m_ops) cv::gapi::s11n::mkOpNode(g, op);
|
||||
cv::gapi::s11n::linkNodes(g);
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@ struct GSerialized {
|
||||
std::vector<cv::gimpl::Data> m_datas;
|
||||
cv::gimpl::DataObjectCounter m_counter;
|
||||
cv::gimpl::Protocol m_proto;
|
||||
|
||||
using data_tag_t = uint64_t;
|
||||
std::map<data_tag_t, cv::gimpl::ConstValue> m_const_datas;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -97,6 +100,9 @@ GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::Op &op);
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::Data &op);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::Data &op);
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::ConstValue &cd);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& os, cv::gimpl::ConstValue &cd);
|
||||
|
||||
// Render types ////////////////////////////////////////////////////////////////
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Text &t);
|
||||
|
||||
@@ -652,7 +652,12 @@ GAPI_OCV_KERNEL(GCPUParseSSDBL, cv::gapi::nn::parsers::GParseSSDBL)
|
||||
std::vector<cv::Rect>& out_boxes,
|
||||
std::vector<int>& out_labels)
|
||||
{
|
||||
cv::parseSSDBL(in_ssd_result, in_size, confidence_threshold, filter_label, out_boxes, out_labels);
|
||||
cv::ParseSSD(in_ssd_result, in_size,
|
||||
confidence_threshold,
|
||||
filter_label,
|
||||
false,
|
||||
false,
|
||||
out_boxes, out_labels);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -665,7 +670,13 @@ GAPI_OCV_KERNEL(GOCVParseSSD, cv::gapi::nn::parsers::GParseSSD)
|
||||
const bool filter_out_of_bounds,
|
||||
std::vector<cv::Rect>& out_boxes)
|
||||
{
|
||||
cv::parseSSD(in_ssd_result, in_size, confidence_threshold, alignment_to_square, filter_out_of_bounds, out_boxes);
|
||||
std::vector<int> unused_labels;
|
||||
cv::ParseSSD(in_ssd_result, in_size,
|
||||
confidence_threshold,
|
||||
-1,
|
||||
alignment_to_square,
|
||||
filter_out_of_bounds,
|
||||
out_boxes, unused_labels);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -170,12 +170,14 @@ private:
|
||||
} // namespace nn
|
||||
} // namespace gapi
|
||||
|
||||
void parseSSDBL(const cv::Mat& in_ssd_result,
|
||||
const cv::Size& in_size,
|
||||
const float confidence_threshold,
|
||||
const int filter_label,
|
||||
std::vector<cv::Rect>& out_boxes,
|
||||
std::vector<int>& out_labels)
|
||||
void ParseSSD(const cv::Mat& in_ssd_result,
|
||||
const cv::Size& in_size,
|
||||
const float confidence_threshold,
|
||||
const int filter_label,
|
||||
const bool alignment_to_square,
|
||||
const bool filter_out_of_bounds,
|
||||
std::vector<cv::Rect>& out_boxes,
|
||||
std::vector<int>& out_labels)
|
||||
{
|
||||
cv::gapi::nn::SSDParser parser(in_ssd_result.size, in_size, in_ssd_result.ptr<float>());
|
||||
out_boxes.clear();
|
||||
@@ -188,38 +190,6 @@ void parseSSDBL(const cv::Mat& in_ssd_result,
|
||||
{
|
||||
std::tie(rc, image_id, confidence, label) = parser.extract(i);
|
||||
|
||||
if (image_id < 0.f)
|
||||
{
|
||||
break; // marks end-of-detections
|
||||
}
|
||||
|
||||
if (confidence < confidence_threshold ||
|
||||
(filter_label != -1 && label != filter_label))
|
||||
{
|
||||
continue; // filter out object classes if filter is specified
|
||||
} // and skip objects with low confidence
|
||||
out_boxes.emplace_back(rc & parser.getSurface());
|
||||
out_labels.emplace_back(label);
|
||||
}
|
||||
}
|
||||
|
||||
void parseSSD(const cv::Mat& in_ssd_result,
|
||||
const cv::Size& in_size,
|
||||
const float confidence_threshold,
|
||||
const bool alignment_to_square,
|
||||
const bool filter_out_of_bounds,
|
||||
std::vector<cv::Rect>& out_boxes)
|
||||
{
|
||||
cv::gapi::nn::SSDParser parser(in_ssd_result.size, in_size, in_ssd_result.ptr<float>());
|
||||
out_boxes.clear();
|
||||
cv::Rect rc;
|
||||
float image_id, confidence;
|
||||
int label;
|
||||
const size_t range = parser.getMaxProposals();
|
||||
for (size_t i = 0; i < range; ++i)
|
||||
{
|
||||
std::tie(rc, image_id, confidence, label) = parser.extract(i);
|
||||
|
||||
if (image_id < 0.f)
|
||||
{
|
||||
break; // marks end-of-detections
|
||||
@@ -228,12 +198,14 @@ void parseSSD(const cv::Mat& in_ssd_result,
|
||||
{
|
||||
continue; // skip objects with low confidence
|
||||
}
|
||||
|
||||
if((filter_label != -1) && (label != filter_label))
|
||||
{
|
||||
continue; // filter out object classes if filter is specified
|
||||
}
|
||||
if (alignment_to_square)
|
||||
{
|
||||
parser.adjustBoundingBox(rc);
|
||||
}
|
||||
|
||||
const auto clipped_rc = rc & parser.getSurface();
|
||||
if (filter_out_of_bounds)
|
||||
{
|
||||
@@ -243,6 +215,7 @@ void parseSSD(const cv::Mat& in_ssd_result,
|
||||
}
|
||||
}
|
||||
out_boxes.emplace_back(clipped_rc);
|
||||
out_labels.emplace_back(label);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,19 +11,14 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
void parseSSDBL(const cv::Mat& in_ssd_result,
|
||||
const cv::Size& in_size,
|
||||
const float confidence_threshold,
|
||||
const int filter_label,
|
||||
std::vector<cv::Rect>& out_boxes,
|
||||
std::vector<int>& out_labels);
|
||||
|
||||
void parseSSD(const cv::Mat& in_ssd_result,
|
||||
void ParseSSD(const cv::Mat& in_ssd_result,
|
||||
const cv::Size& in_size,
|
||||
const float confidence_threshold,
|
||||
const int filter_label,
|
||||
const bool alignment_to_square,
|
||||
const bool filter_out_of_bounds,
|
||||
std::vector<cv::Rect>& out_boxes);
|
||||
std::vector<cv::Rect>& out_boxes,
|
||||
std::vector<int>& out_labels);
|
||||
|
||||
void parseYolo(const cv::Mat& in_yolo_result,
|
||||
const cv::Size& in_size,
|
||||
|
||||
@@ -37,3 +37,15 @@ cv::gapi::ie::PyParams cv::gapi::ie::params(const std::string &tag,
|
||||
const std::string &device) {
|
||||
return {tag, model, device};
|
||||
}
|
||||
|
||||
cv::gapi::ie::PyParams& cv::gapi::ie::PyParams::constInput(const std::string &layer_name,
|
||||
const cv::Mat &data,
|
||||
TraitAs hint) {
|
||||
m_priv->constInput(layer_name, data, hint);
|
||||
return *this;
|
||||
}
|
||||
|
||||
cv::gapi::ie::PyParams& cv::gapi::ie::PyParams::cfgNumRequests(size_t nireq) {
|
||||
m_priv->cfgNumRequests(nireq);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -108,6 +108,7 @@ inline IE::Precision toIE(int depth) {
|
||||
case CV_8U: return IE::Precision::U8;
|
||||
case CV_32S: return IE::Precision::I32;
|
||||
case CV_32F: return IE::Precision::FP32;
|
||||
case CV_16F: return IE::Precision::FP16;
|
||||
default: GAPI_Assert(false && "IE. Unsupported data type");
|
||||
}
|
||||
return IE::Precision::UNSPECIFIED;
|
||||
@@ -161,6 +162,7 @@ inline IE::Blob::Ptr wrapIE(const cv::Mat &mat, cv::gapi::ie::TraitAs hint) {
|
||||
HANDLE(8U, uint8_t);
|
||||
HANDLE(32F, float);
|
||||
HANDLE(32S, int);
|
||||
HANDLE(16F, int16_t);
|
||||
#undef HANDLE
|
||||
default: GAPI_Assert(false && "IE. Unsupported data type");
|
||||
}
|
||||
@@ -222,8 +224,17 @@ struct IEUnit {
|
||||
IE::ExecutableNetwork this_network;
|
||||
cv::gimpl::ie::wrap::Plugin this_plugin;
|
||||
|
||||
InferenceEngine::RemoteContext::Ptr rctx = nullptr;
|
||||
|
||||
explicit IEUnit(const cv::gapi::ie::detail::ParamDesc &pp)
|
||||
: params(pp) {
|
||||
InferenceEngine::ParamMap* ctx_params =
|
||||
cv::util::any_cast<InferenceEngine::ParamMap>(¶ms.context_config);
|
||||
if (ctx_params != nullptr) {
|
||||
auto ie_core = cv::gimpl::ie::wrap::getCore();
|
||||
rctx = ie_core.CreateContext(params.device_id, *ctx_params);
|
||||
}
|
||||
|
||||
if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
net = cv::gimpl::ie::wrap::readNetwork(params);
|
||||
inputs = net.getInputsInfo();
|
||||
@@ -231,11 +242,7 @@ struct IEUnit {
|
||||
} else if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import) {
|
||||
this_plugin = cv::gimpl::ie::wrap::getPlugin(params);
|
||||
this_plugin.SetConfig(params.config);
|
||||
this_network = cv::gimpl::ie::wrap::importNetwork(this_plugin, params);
|
||||
// FIXME: ICNNetwork returns InputsDataMap/OutputsDataMap,
|
||||
// but ExecutableNetwork returns ConstInputsDataMap/ConstOutputsDataMap
|
||||
inputs = cv::gimpl::ie::wrap::toInputsDataMap(this_network.GetInputsInfo());
|
||||
outputs = cv::gimpl::ie::wrap::toOutputsDataMap(this_network.GetOutputsInfo());
|
||||
this_network = cv::gimpl::ie::wrap::importNetwork(this_plugin, params, rctx);
|
||||
if (!params.reshape_table.empty() || !params.layer_names_to_reshape.empty()) {
|
||||
GAPI_LOG_WARNING(NULL, "Reshape isn't supported for imported network");
|
||||
}
|
||||
@@ -259,10 +266,18 @@ struct IEUnit {
|
||||
+ params.model_path));
|
||||
}
|
||||
if (params.num_in == 1u && params.input_names.empty()) {
|
||||
params.input_names = { inputs.begin()->first };
|
||||
if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
params.input_names = { inputs.begin()->first };
|
||||
} else {
|
||||
params.input_names = { this_network.GetInputsInfo().begin()->first };
|
||||
}
|
||||
}
|
||||
if (params.num_out == 1u && params.output_names.empty()) {
|
||||
params.output_names = { outputs.begin()->first };
|
||||
if (params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
params.output_names = { outputs.begin()->first };
|
||||
} else {
|
||||
params.output_names = { this_network.GetOutputsInfo().begin()->first };
|
||||
}
|
||||
}
|
||||
if (!params.reshape_table.empty()) {
|
||||
GAPI_Assert((params.reshape_table.size() + params.layer_names_to_reshape.size()) <=
|
||||
@@ -279,7 +294,8 @@ struct IEUnit {
|
||||
// for loadNetwork they can be obtained by using readNetwork
|
||||
non_const_this->this_plugin = cv::gimpl::ie::wrap::getPlugin(params);
|
||||
non_const_this->this_plugin.SetConfig(params.config);
|
||||
non_const_this->this_network = cv::gimpl::ie::wrap::loadNetwork(non_const_this->this_plugin, net, params);
|
||||
non_const_this->this_network = cv::gimpl::ie::wrap::loadNetwork(non_const_this->this_plugin,
|
||||
net, params, rctx);
|
||||
}
|
||||
|
||||
return {params, this_plugin, this_network};
|
||||
@@ -481,7 +497,32 @@ using GConstGIEModel = ade::ConstTypedGraph
|
||||
, IECallable
|
||||
>;
|
||||
|
||||
inline IE::Blob::Ptr extractRemoteBlob(IECallContext& ctx, std::size_t i) {
|
||||
GAPI_Assert(ctx.inShape(i) == cv::GShape::GFRAME &&
|
||||
"Remote blob is supported for MediaFrame only");
|
||||
|
||||
cv::util::any any_blob_params = ctx.inFrame(i).blobParams();
|
||||
auto ie_core = cv::gimpl::ie::wrap::getCore();
|
||||
|
||||
using ParamType = std::pair<InferenceEngine::TensorDesc,
|
||||
InferenceEngine::ParamMap>;
|
||||
|
||||
ParamType* blob_params = cv::util::any_cast<ParamType>(&any_blob_params);
|
||||
if (blob_params == nullptr) {
|
||||
GAPI_Assert(false && "Incorrect type of blobParams: "
|
||||
"expected std::pair<InferenceEngine::TensorDesc,"
|
||||
"InferenceEngine::ParamMap>");
|
||||
}
|
||||
|
||||
return ctx.uu.rctx->CreateBlob(blob_params->first,
|
||||
blob_params->second);
|
||||
}
|
||||
|
||||
inline IE::Blob::Ptr extractBlob(IECallContext& ctx, std::size_t i) {
|
||||
if (ctx.uu.rctx != nullptr) {
|
||||
return extractRemoteBlob(ctx, i);
|
||||
}
|
||||
|
||||
switch (ctx.inShape(i)) {
|
||||
case cv::GShape::GFRAME: {
|
||||
const auto& frame = ctx.inFrame(i);
|
||||
@@ -496,6 +537,24 @@ inline IE::Blob::Ptr extractBlob(IECallContext& ctx, std::size_t i) {
|
||||
}
|
||||
GAPI_Assert(false);
|
||||
}
|
||||
|
||||
|
||||
static void setBlob(InferenceEngine::InferRequest& req,
|
||||
cv::gapi::ie::detail::ParamDesc::Kind kind,
|
||||
const std::string& layer_name,
|
||||
IE::Blob::Ptr blob) {
|
||||
// NB: In case importNetwork preprocessing must be
|
||||
// passed as SetBlob argument.
|
||||
if (kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
req.SetBlob(layer_name, blob);
|
||||
} else {
|
||||
GAPI_Assert(kind == cv::gapi::ie::detail::ParamDesc::Kind::Import);
|
||||
IE::PreProcessInfo info;
|
||||
info.setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
req.SetBlob(layer_name, blob, info);
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
std::vector<InferenceEngine::InferRequest> cv::gimpl::ie::IECompiled::createInferRequests() {
|
||||
@@ -571,6 +630,11 @@ void cv::gimpl::ie::RequestPool::callback(cv::gimpl::ie::RequestPool::Task task,
|
||||
InferenceEngine::InferRequest& request,
|
||||
size_t id) {
|
||||
task.callback(request);
|
||||
// NB: IE::InferRequest keeps the callback until the new one is set.
|
||||
// Since user's callback might keep resources that should be released,
|
||||
// need to destroy its after execution.
|
||||
// Let's set the empty one to cause the destruction of a callback.
|
||||
request.SetCompletionCallback([](){});
|
||||
m_idle_ids.push(id);
|
||||
}
|
||||
|
||||
@@ -772,7 +836,6 @@ static void PostOutputs(InferenceEngine::InferRequest &request,
|
||||
auto output = ctx->output(i);
|
||||
ctx->out.meta(output, ctx->input(0).meta);
|
||||
ctx->out.post(std::move(output));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,25 +917,30 @@ struct Infer: public cv::detail::KernelTag {
|
||||
// meta order.
|
||||
GAPI_Assert(uu.params.input_names.size() == in_metas.size()
|
||||
&& "Known input layers count doesn't match input meta count");
|
||||
for (auto &&it : ade::util::zip(ade::util::toRange(uu.params.input_names),
|
||||
ade::util::toRange(in_metas))) {
|
||||
const auto &input_name = std::get<0>(it);
|
||||
auto &&ii = uu.inputs.at(input_name);
|
||||
const auto & mm = std::get<1>(it);
|
||||
|
||||
configureInputInfo(ii, mm);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm, input_reshape_table);
|
||||
// NB: Configuring input precision and network reshape must be done
|
||||
// only in the loadNetwork case.
|
||||
if (uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
for (auto &&it : ade::util::zip(ade::util::toRange(uu.params.input_names),
|
||||
ade::util::toRange(in_metas))) {
|
||||
const auto &input_name = std::get<0>(it);
|
||||
auto &&ii = uu.inputs.at(input_name);
|
||||
const auto & mm = std::get<1>(it);
|
||||
|
||||
configureInputInfo(ii, mm);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm, input_reshape_table);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
}
|
||||
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: It would be nice here to have an exact number of network's
|
||||
@@ -904,7 +972,10 @@ struct Infer: public cv::detail::KernelTag {
|
||||
// and redirect our data producers to this memory
|
||||
// (A memory dialog comes to the picture again)
|
||||
IE::Blob::Ptr this_blob = extractBlob(*ctx, i);
|
||||
req.SetBlob(ctx->uu.params.input_names[i], this_blob);
|
||||
setBlob(req,
|
||||
ctx->uu.params.kind,
|
||||
ctx->uu.params.input_names[i],
|
||||
this_blob);
|
||||
}
|
||||
// FIXME: Should it be done by kernel ?
|
||||
// What about to do that in RequestPool ?
|
||||
@@ -936,22 +1007,26 @@ struct InferROI: public cv::detail::KernelTag {
|
||||
GAPI_Assert(1u == uu.params.input_names.size());
|
||||
GAPI_Assert(2u == in_metas.size());
|
||||
|
||||
// 0th is ROI, 1st is input image
|
||||
const auto &input_name = uu.params.input_names.at(0);
|
||||
auto &&ii = uu.inputs.at(input_name);
|
||||
auto &&mm = in_metas.at(1u);
|
||||
configureInputInfo(ii, mm);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm, input_reshape_table);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
// NB: Configuring input precision and network reshape must be done
|
||||
// only in the loadNetwork case.
|
||||
if (uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
// 0th is ROI, 1st is input image
|
||||
const auto &input_name = uu.params.input_names.at(0);
|
||||
auto &&ii = uu.inputs.at(input_name);
|
||||
auto &&mm = in_metas.at(1u);
|
||||
configureInputInfo(ii, mm);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm, input_reshape_table);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: It would be nice here to have an exact number of network's
|
||||
@@ -980,10 +1055,11 @@ struct InferROI: public cv::detail::KernelTag {
|
||||
auto&& this_roi = ctx->inArg<cv::detail::OpaqueRef>(0).rref<cv::Rect>();
|
||||
|
||||
IE::Blob::Ptr this_blob = extractBlob(*ctx, 1);
|
||||
|
||||
req.SetBlob(*(ctx->uu.params.input_names.begin()),
|
||||
IE::make_shared_blob(this_blob, toIE(this_roi)));
|
||||
|
||||
setBlob(req,
|
||||
ctx->uu.params.kind,
|
||||
*(ctx->uu.params.input_names.begin()),
|
||||
IE::make_shared_blob(this_blob,
|
||||
toIE(this_roi)));
|
||||
// FIXME: Should it be done by kernel ?
|
||||
// What about to do that in RequestPool ?
|
||||
req.StartAsync();
|
||||
@@ -1018,23 +1094,27 @@ struct InferList: public cv::detail::KernelTag {
|
||||
GAPI_Assert(uu.params.input_names.size() == (in_metas.size() - 1u)
|
||||
&& "Known input layers count doesn't match input meta count");
|
||||
|
||||
std::size_t idx = 1u;
|
||||
for (auto &&input_name : uu.params.input_names) {
|
||||
auto &&ii = uu.inputs.at(input_name);
|
||||
const auto & mm = in_metas[idx++];
|
||||
configureInputInfo(ii, mm);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm, input_reshape_table);
|
||||
// NB: Configuring input precision and network reshape must be done
|
||||
// only in the loadNetwork case.
|
||||
if (uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
std::size_t idx = 1u;
|
||||
for (auto &&input_name : uu.params.input_names) {
|
||||
auto &&ii = uu.inputs.at(input_name);
|
||||
const auto & mm = in_metas[idx++];
|
||||
configureInputInfo(ii, mm);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm, input_reshape_table);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
}
|
||||
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
}
|
||||
}
|
||||
|
||||
// roi-list version is much easier at the moment.
|
||||
@@ -1060,6 +1140,7 @@ struct InferList: public cv::detail::KernelTag {
|
||||
}
|
||||
|
||||
IE::Blob::Ptr this_blob = extractBlob(*ctx, 1);
|
||||
|
||||
std::vector<std::vector<int>> cached_dims(ctx->uu.params.num_out);
|
||||
for (auto i : ade::util::iota(ctx->uu.params.num_out)) {
|
||||
const IE::DataPtr& ie_out = ctx->uu.outputs.at(ctx->uu.params.output_names[i]);
|
||||
@@ -1079,7 +1160,10 @@ struct InferList: public cv::detail::KernelTag {
|
||||
cv::gimpl::ie::RequestPool::Task {
|
||||
[ctx, rc, this_blob](InferenceEngine::InferRequest &req) {
|
||||
IE::Blob::Ptr roi_blob = IE::make_shared_blob(this_blob, toIE(rc));
|
||||
req.SetBlob(ctx->uu.params.input_names[0u], roi_blob);
|
||||
setBlob(req,
|
||||
ctx->uu.params.kind,
|
||||
ctx->uu.params.input_names[0u],
|
||||
roi_blob);
|
||||
req.StartAsync();
|
||||
},
|
||||
std::bind(callback, std::placeholders::_1, pos)
|
||||
@@ -1153,19 +1237,23 @@ struct InferList2: public cv::detail::KernelTag {
|
||||
&& "Non-array inputs are not supported");
|
||||
|
||||
if (op.k.inKinds[idx] == cv::detail::OpaqueKind::CV_RECT) {
|
||||
// This is a cv::Rect -- configure the IE preprocessing
|
||||
configureInputInfo(ii, mm_0);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm_0, input_reshape_table);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
// NB: Configuring input precision and network reshape must be done
|
||||
// only in the loadNetwork case.
|
||||
if (uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
// This is a cv::Rect -- configure the IE preprocessing
|
||||
configureInputInfo(ii, mm_0);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
configureInputReshapeByImage(ii, mm_0, input_reshape_table);
|
||||
}
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
// FIXME: This isn't the best place to call reshape function.
|
||||
// Сorrect solution would be to do this in compile() method of network,
|
||||
// but now input meta isn't passed to compile() method.
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// This is a cv::GMat (equals to: cv::Mat)
|
||||
@@ -1230,8 +1318,10 @@ struct InferList2: public cv::detail::KernelTag {
|
||||
GAPI_Assert(false &&
|
||||
"Only Rect and Mat types are supported for infer list 2!");
|
||||
}
|
||||
|
||||
req.SetBlob(ctx->uu.params.input_names[in_idx], this_blob);
|
||||
setBlob(req,
|
||||
ctx->uu.params.kind,
|
||||
ctx->uu.params.input_names[in_idx],
|
||||
this_blob);
|
||||
}
|
||||
req.StartAsync();
|
||||
},
|
||||
|
||||
@@ -22,24 +22,6 @@ namespace IE = InferenceEngine;
|
||||
namespace giewrap = cv::gimpl::ie::wrap;
|
||||
using GIEParam = cv::gapi::ie::detail::ParamDesc;
|
||||
|
||||
IE::InputsDataMap giewrap::toInputsDataMap (const IE::ConstInputsDataMap& inputs) {
|
||||
IE::InputsDataMap transformed;
|
||||
auto convert = [](const std::pair<std::string, IE::InputInfo::CPtr>& p) {
|
||||
return std::make_pair(p.first, std::const_pointer_cast<IE::InputInfo>(p.second));
|
||||
};
|
||||
std::transform(inputs.begin(), inputs.end(), std::inserter(transformed, transformed.end()), convert);
|
||||
return transformed;
|
||||
}
|
||||
|
||||
IE::OutputsDataMap giewrap::toOutputsDataMap (const IE::ConstOutputsDataMap& outputs) {
|
||||
IE::OutputsDataMap transformed;
|
||||
auto convert = [](const std::pair<std::string, IE::CDataPtr>& p) {
|
||||
return std::make_pair(p.first, std::const_pointer_cast<IE::Data>(p.second));
|
||||
};
|
||||
std::transform(outputs.begin(), outputs.end(), std::inserter(transformed, transformed.end()), convert);
|
||||
return transformed;
|
||||
}
|
||||
|
||||
#if INF_ENGINE_RELEASE < 2020000000 // < 2020.1
|
||||
// Load extensions (taken from DNN module)
|
||||
std::vector<std::string> giewrap::getExtensions(const GIEParam& params) {
|
||||
@@ -124,7 +106,11 @@ IE::Core giewrap::getPlugin(const GIEParam& params) {
|
||||
{
|
||||
try
|
||||
{
|
||||
#if INF_ENGINE_RELEASE >= 2021040000
|
||||
plugin.AddExtension(std::make_shared<IE::Extension>(extlib), params.device_id);
|
||||
#else
|
||||
plugin.AddExtension(IE::make_so_pointer<IE::IExtension>(extlib), params.device_id);
|
||||
#endif
|
||||
CV_LOG_INFO(NULL, "DNN-IE: Loaded extension plugin: " << extlib);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#include "opencv2/gapi/infer/ie.hpp"
|
||||
|
||||
@@ -28,9 +29,6 @@ namespace wrap {
|
||||
GAPI_EXPORTS std::vector<std::string> getExtensions(const GIEParam& params);
|
||||
GAPI_EXPORTS IE::CNNNetwork readNetwork(const GIEParam& params);
|
||||
|
||||
IE::InputsDataMap toInputsDataMap (const IE::ConstInputsDataMap& inputs);
|
||||
IE::OutputsDataMap toOutputsDataMap(const IE::ConstOutputsDataMap& outputs);
|
||||
|
||||
#if INF_ENGINE_RELEASE < 2019020000 // < 2019.R2
|
||||
using Plugin = IE::InferencePlugin;
|
||||
GAPI_EXPORTS IE::InferencePlugin getPlugin(const GIEParam& params);
|
||||
@@ -50,12 +48,29 @@ GAPI_EXPORTS IE::Core getCore();
|
||||
GAPI_EXPORTS IE::Core getPlugin(const GIEParam& params);
|
||||
GAPI_EXPORTS inline IE::ExecutableNetwork loadNetwork( IE::Core& core,
|
||||
const IE::CNNNetwork& net,
|
||||
const GIEParam& params) {
|
||||
return core.LoadNetwork(net, params.device_id);
|
||||
const GIEParam& params,
|
||||
IE::RemoteContext::Ptr rctx = nullptr) {
|
||||
if (rctx != nullptr) {
|
||||
return core.LoadNetwork(net, rctx);
|
||||
} else {
|
||||
return core.LoadNetwork(net, params.device_id);
|
||||
}
|
||||
}
|
||||
GAPI_EXPORTS inline IE::ExecutableNetwork importNetwork( IE::Core& core,
|
||||
const GIEParam& param) {
|
||||
return core.ImportNetwork(param.model_path, param.device_id, {});
|
||||
const GIEParam& params,
|
||||
IE::RemoteContext::Ptr rctx = nullptr) {
|
||||
if (rctx != nullptr) {
|
||||
std::filebuf blobFile;
|
||||
if (!blobFile.open(params.model_path, std::ios::in | std::ios::binary))
|
||||
{
|
||||
blobFile.close();
|
||||
throw std::runtime_error("Could not open file");
|
||||
}
|
||||
std::istream graphBlob(&blobFile);
|
||||
return core.ImportNetwork(graphBlob, rctx);
|
||||
} else {
|
||||
return core.ImportNetwork(params.model_path, params.device_id, {});
|
||||
}
|
||||
}
|
||||
#endif // INF_ENGINE_RELEASE < 2019020000
|
||||
}}}}
|
||||
|
||||
Reference in New Issue
Block a user