mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -456,6 +456,7 @@ public:
|
||||
cv::gimpl::GIslandExecutable::IOutput & output,
|
||||
const cv::GArgs & args,
|
||||
const std::vector<cv::gimpl::RcDesc> & outs,
|
||||
cv::GRunArg::Meta && meta,
|
||||
std::vector<cv::gimpl::GIslandExecutable::InObj> && input_objs,
|
||||
std::vector<cv::gimpl::GIslandExecutable::OutObj> && output_objs);
|
||||
|
||||
@@ -477,9 +478,8 @@ public:
|
||||
const cv::Mat& inMat (std::size_t input) const;
|
||||
const cv::MediaFrame& inFrame(std::size_t input) const;
|
||||
|
||||
const cv::GRunArg& input (std::size_t idx) const;
|
||||
cv::GRunArgP output (std::size_t idx);
|
||||
cv::Mat& outMatR(std::size_t idx);
|
||||
cv::GRunArgP output (std::size_t idx);
|
||||
cv::Mat& outMatR(std::size_t idx);
|
||||
|
||||
const IEUnit &uu;
|
||||
cv::gimpl::GIslandExecutable::IOutput &out;
|
||||
@@ -491,6 +491,8 @@ public:
|
||||
// To store exception appeared in callback.
|
||||
std::exception_ptr eptr;
|
||||
|
||||
const cv::GRunArg::Meta& getMeta() { return m_meta; };
|
||||
|
||||
using req_key_t = void*;
|
||||
cv::MediaFrame* prepareKeepAliveFrameSlot(req_key_t key);
|
||||
size_t releaseKeepAliveFrame(req_key_t key);
|
||||
@@ -499,6 +501,9 @@ private:
|
||||
|
||||
cv::GArg packArg(const cv::GArg &arg);
|
||||
|
||||
// To propagate accumulated meta from all inputs to output.
|
||||
cv::GRunArg::Meta m_meta;
|
||||
|
||||
// To store input/output data from frames
|
||||
std::vector<cv::gimpl::GIslandExecutable::InObj> m_input_objs;
|
||||
std::vector<cv::gimpl::GIslandExecutable::OutObj> m_output_objs;
|
||||
@@ -525,9 +530,11 @@ IECallContext::IECallContext(const IEUnit &
|
||||
cv::gimpl::GIslandExecutable::IOutput & output,
|
||||
const cv::GArgs & args,
|
||||
const std::vector<cv::gimpl::RcDesc> & outs,
|
||||
cv::GRunArg::Meta && meta,
|
||||
std::vector<cv::gimpl::GIslandExecutable::InObj> && input_objs,
|
||||
std::vector<cv::gimpl::GIslandExecutable::OutObj> && output_objs)
|
||||
: uu(unit), out(output), m_input_objs(std::move(input_objs)), m_output_objs(std::move(output_objs))
|
||||
: uu(unit), out(output), m_meta(std::move(meta)),
|
||||
m_input_objs(std::move(input_objs)), m_output_objs(std::move(output_objs))
|
||||
{
|
||||
for (auto& it : m_input_objs) cv::gimpl::magazine::bindInArg (m_res, it.first, it.second);
|
||||
for (auto& it : m_output_objs) cv::gimpl::magazine::bindOutArg(m_res, it.first, it.second);
|
||||
@@ -575,10 +582,6 @@ cv::GRunArgP IECallContext::output(std::size_t idx) {
|
||||
return m_output_objs[idx].second;
|
||||
};
|
||||
|
||||
const cv::GRunArg& IECallContext::input(std::size_t idx) const {
|
||||
return m_input_objs[idx].second;
|
||||
}
|
||||
|
||||
cv::detail::VectorRef& IECallContext::outVecRef(std::size_t idx) {
|
||||
return cv::util::get<cv::detail::VectorRef>(m_results.at(idx));
|
||||
}
|
||||
@@ -1062,6 +1065,12 @@ void cv::gimpl::ie::GIEExecutable::run(cv::gimpl::GIslandExecutable::IInput &in
|
||||
|
||||
GAPI_Assert(cv::util::holds_alternative<cv::GRunArgs>(in_msg));
|
||||
const auto in_vector = cv::util::get<cv::GRunArgs>(in_msg);
|
||||
// NB: Collect meta from all inputs.
|
||||
cv::GRunArg::Meta stub_meta;
|
||||
for (auto &&in_arg : in_vector)
|
||||
{
|
||||
stub_meta.insert(in_arg.meta.begin(), in_arg.meta.end());
|
||||
}
|
||||
|
||||
// (1) Collect island inputs/outputs
|
||||
input_objs.reserve(in_desc.size());
|
||||
@@ -1084,7 +1093,7 @@ void cv::gimpl::ie::GIEExecutable::run(cv::gimpl::GIslandExecutable::IInput &in
|
||||
const auto &op = m_gm.metadata(this_nh).get<Op>();
|
||||
// (2) Create kernel context
|
||||
auto ctx = std::make_shared<IECallContext>(uu, out, op.args, op.outs,
|
||||
std::move(input_objs), std::move(output_objs));
|
||||
std::move(stub_meta), std::move(input_objs), std::move(output_objs));
|
||||
|
||||
const auto &kk = giem.metadata(this_nh).get<IECallable>();
|
||||
|
||||
@@ -1096,6 +1105,7 @@ void cv::gimpl::ie::GIEExecutable::run(cv::gimpl::GIslandExecutable::IInput &in
|
||||
for (auto i : ade::util::iota(ctx->uu.params.num_out))
|
||||
{
|
||||
auto output = ctx->output(i);
|
||||
ctx->out.meta(output, ctx->getMeta());
|
||||
ctx->out.post(std::move(output), eptr);
|
||||
}
|
||||
return;
|
||||
@@ -1247,7 +1257,7 @@ static void PostOutputs(InferenceEngine::InferRequest &request,
|
||||
IE::Blob::Ptr this_blob = request.GetBlob(ctx->uu.params.output_names[i]);
|
||||
copyFromIE(this_blob, out_mat);
|
||||
auto output = ctx->output(i);
|
||||
ctx->out.meta(output, ctx->input(0).meta);
|
||||
ctx->out.meta(output, ctx->getMeta());
|
||||
ctx->out.post(std::move(output), ctx->eptr);
|
||||
}
|
||||
|
||||
@@ -1314,7 +1324,7 @@ void PostOutputsList::operator()(InferenceEngine::InferRequest &req,
|
||||
if (finished == size) {
|
||||
for (auto i : ade::util::iota(ctx->uu.params.num_out)) {
|
||||
auto output = ctx->output(i);
|
||||
ctx->out.meta(output, ctx->input(0).meta);
|
||||
ctx->out.meta(output, ctx->getMeta());
|
||||
ctx->out.post(std::move(output), ctx->eptr);
|
||||
}
|
||||
}
|
||||
@@ -1374,6 +1384,11 @@ struct Infer: public cv::detail::KernelTag {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &&p : uu.params.const_inputs) {
|
||||
const auto ii = inputs.at(p.first);
|
||||
ii->setPrecision(toIE(p.second.first.depth()));
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -1474,7 +1489,8 @@ struct InferROI: public cv::detail::KernelTag {
|
||||
// only in the loadNetwork case.
|
||||
if (uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Load) {
|
||||
// 0th is ROI, 1st is input image
|
||||
auto ii = uu.net.getInputsInfo().at(input_name);
|
||||
auto inputs = uu.net.getInputsInfo();
|
||||
auto ii = inputs.at(input_name);
|
||||
configureInputInfo(ii, mm);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
@@ -1496,6 +1512,11 @@ struct InferROI: public cv::detail::KernelTag {
|
||||
const_cast<IEUnit::InputFramesDesc &>(uu.net_input_params)
|
||||
.set_param(input_name, ii->getTensorDesc());
|
||||
}
|
||||
|
||||
for (auto &&p : uu.params.const_inputs) {
|
||||
inputs.at(p.first)->setPrecision(toIE(p.second.first.depth()));
|
||||
}
|
||||
|
||||
configureOutputPrecision(uu.net.getOutputsInfo(), uu.params.output_precision);
|
||||
} else {
|
||||
GAPI_Assert(uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import);
|
||||
@@ -1614,6 +1635,12 @@ struct InferList: public cv::detail::KernelTag {
|
||||
if (!input_reshape_table.empty()) {
|
||||
const_cast<IE::CNNNetwork *>(&uu.net)->reshape(input_reshape_table);
|
||||
}
|
||||
|
||||
for (auto &&p : uu.params.const_inputs) {
|
||||
const auto ii = inputs.at(p.first);
|
||||
ii->setPrecision(toIE(p.second.first.depth()));
|
||||
}
|
||||
|
||||
configureOutputPrecision(uu.net.getOutputsInfo(), uu.params.output_precision);
|
||||
} else {
|
||||
GAPI_Assert(uu.params.kind == cv::gapi::ie::detail::ParamDesc::Kind::Import);
|
||||
@@ -1642,7 +1669,7 @@ struct InferList: public cv::detail::KernelTag {
|
||||
if (in_roi_vec.empty()) {
|
||||
for (auto i : ade::util::iota(ctx->uu.params.num_out)) {
|
||||
auto output = ctx->output(i);
|
||||
ctx->out.meta(output, ctx->input(0).meta);
|
||||
ctx->out.meta(output, ctx->getMeta());
|
||||
ctx->out.post(std::move(output));
|
||||
}
|
||||
return;
|
||||
@@ -1751,8 +1778,9 @@ struct InferList2: public cv::detail::KernelTag {
|
||||
// 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) {
|
||||
auto inputs = uu.net.getInputsInfo();
|
||||
// This is a cv::Rect -- configure the IE preprocessing
|
||||
auto ii = uu.net.getInputsInfo().at(input_name);
|
||||
auto ii = inputs.at(input_name);
|
||||
configureInputInfo(ii, mm_0);
|
||||
if (uu.params.layer_names_to_reshape.find(input_name) !=
|
||||
uu.params.layer_names_to_reshape.end()) {
|
||||
@@ -1762,6 +1790,10 @@ struct InferList2: public cv::detail::KernelTag {
|
||||
ii->getPreProcess().setResizeAlgorithm(IE::RESIZE_BILINEAR);
|
||||
}
|
||||
|
||||
for (auto &&p : uu.params.const_inputs) {
|
||||
inputs.at(p.first)->setPrecision(toIE(p.second.first.depth()));
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -1806,7 +1838,7 @@ struct InferList2: public cv::detail::KernelTag {
|
||||
if (list_size == 0u) {
|
||||
for (auto i : ade::util::iota(ctx->uu.params.num_out)) {
|
||||
auto output = ctx->output(i);
|
||||
ctx->out.meta(output, ctx->input(0).meta);
|
||||
ctx->out.meta(output, ctx->getMeta());
|
||||
ctx->out.post(std::move(output));
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -8,6 +8,19 @@ cv::gapi::onnx::PyParams::PyParams(const std::string& tag,
|
||||
const std::string& model_path)
|
||||
: m_priv(std::make_shared<Params<cv::gapi::Generic>>(tag, model_path)) {}
|
||||
|
||||
cv::gapi::onnx::PyParams& cv::gapi::onnx::PyParams::cfgMeanStd(const std::string &layer_name,
|
||||
const cv::Scalar &m,
|
||||
const cv::Scalar &s) {
|
||||
m_priv->cfgMeanStdDev(layer_name, m, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
cv::gapi::onnx::PyParams& cv::gapi::onnx::PyParams::cfgNormalize(const std::string &layer_name,
|
||||
bool flag) {
|
||||
m_priv->cfgNormalize(layer_name, flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
cv::gapi::GBackend cv::gapi::onnx::PyParams::backend() const {
|
||||
return m_priv->backend();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ static std::string pdims(const std::vector<int64_t> &dims) {
|
||||
|
||||
struct TensorInfo {
|
||||
TensorInfo() = default;
|
||||
explicit TensorInfo(const Ort::TensorTypeAndShapeInfo& info)
|
||||
|
||||
explicit TensorInfo(const Ort::ConstTensorTypeAndShapeInfo &info)
|
||||
: dims(info.GetShape())
|
||||
, type(info.GetElementType())
|
||||
, is_dynamic(ade::util::find(dims, -1) != dims.end()) {
|
||||
@@ -283,6 +284,7 @@ inline void preprocess(const cv::Mat& src,
|
||||
cv::resize(csc, rsz, cv::Size(new_w, new_h));
|
||||
if (src.depth() == CV_8U && type == CV_32F) {
|
||||
rsz.convertTo(pp, type, ti.normalize ? 1.f / 255 : 1.f);
|
||||
|
||||
if (ti.mstd.has_value()) {
|
||||
pp -= ti.mstd->mean;
|
||||
pp /= ti.mstd->stdev;
|
||||
@@ -688,11 +690,10 @@ std::vector<TensorInfo> ONNXCompiled::getTensorInfo(TensorPosition pos) {
|
||||
: this_session.GetOutputTypeInfo(i);
|
||||
tensor_info.emplace_back(info.GetTensorTypeAndShapeInfo());
|
||||
|
||||
char *name_p = pos == INPUT
|
||||
? this_session.GetInputName(i, allocator)
|
||||
: this_session.GetOutputName(i, allocator);
|
||||
tensor_info.back().name = name_p;
|
||||
allocator.Free(name_p);
|
||||
Ort::AllocatedStringPtr name_p = pos == INPUT
|
||||
? this_session.GetInputNameAllocated(i, allocator)
|
||||
: this_session.GetOutputNameAllocated(i, allocator);
|
||||
tensor_info.back().name = std::string(name_p.get());
|
||||
}
|
||||
|
||||
return tensor_info;
|
||||
@@ -1143,24 +1144,31 @@ namespace {
|
||||
if (pp.is_generic) {
|
||||
auto& info = cv::util::any_cast<cv::detail::InOutInfo>(op.params);
|
||||
|
||||
for (const auto& a : info.in_names)
|
||||
for (const auto& layer_name : info.in_names)
|
||||
{
|
||||
pp.input_names.push_back(a);
|
||||
}
|
||||
// Adding const input is necessary because the definition of input_names
|
||||
// includes const input.
|
||||
for (const auto& a : pp.const_inputs)
|
||||
{
|
||||
pp.input_names.push_back(a.first);
|
||||
pp.input_names.push_back(layer_name);
|
||||
if (!pp.generic_mstd.empty()) {
|
||||
const auto &ms = pp.generic_mstd.at(layer_name);
|
||||
pp.mean.push_back(ms.first);
|
||||
pp.stdev.push_back(ms.second);
|
||||
}
|
||||
if (!pp.generic_norm.empty()) {
|
||||
pp.normalize.push_back(pp.generic_norm.at(layer_name));
|
||||
}
|
||||
}
|
||||
pp.num_in = info.in_names.size();
|
||||
|
||||
// Incorporate extra parameters associated with input layer names
|
||||
// FIXME(DM): The current form assumes ALL input layers require
|
||||
// this information, this is obviously not correct
|
||||
|
||||
for (const auto& a : info.out_names)
|
||||
{
|
||||
pp.output_names.push_back(a);
|
||||
}
|
||||
pp.num_out = info.out_names.size();
|
||||
}
|
||||
} // if(is_generic) -- note, the structure is already filled at the user
|
||||
// end when a non-generic Params are used
|
||||
|
||||
gm.metadata(nh).set(ONNXUnit{pp});
|
||||
gm.metadata(nh).set(ONNXCallable{ki.run});
|
||||
|
||||
Reference in New Issue
Block a user