1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #15090 from dmatveev:dm/ng-0001-g-api-inference-api

* G-API-NG/API: Introduced inference API and IE-based backend

- Very quick-n-dirty implementation
- OpenCV's own DNN module is not used
- No tests so far

* G-API-NG/IE: Refined IE backend, added more tests

* G-API-NG/IE: Fixed various CI warnings & build issues + tests

- Added tests on multi-dimensional own::Mat
- Added tests on GMatDesc with dimensions
- Documentation on infer.hpp
- Fixed more warnings + added a ROI list test
- Fix descr_of clash for vector<Mat> & standalone mode
- Fix build issue with gcc-4.8x
- Addressed review comments

* G-API-NG/IE: Addressed review comments

- Pass `false` to findDataFile()
- Add deprecation warning suppression macros for IE
This commit is contained in:
Dmitry Matveev
2019-08-05 17:56:34 +03:00
committed by Alexander Alekhin
parent 59b0314a0e
commit 0757a51e2b
32 changed files with 1974 additions and 85 deletions
+29 -10
View File
@@ -7,6 +7,7 @@
#include "precomp.hpp"
#include <memory> // unique_ptr
#include <functional> // multiplies
#include <opencv2/gapi/gkernel.hpp>
#include <opencv2/gapi/own/convert.hpp>
@@ -355,21 +356,39 @@ void writeBack(const Mag& mag, const RcDesc &rc, GRunArgP &g_arg, bool is_umat)
} // namespace magazine
void createMat(const cv::GMatDesc desc, cv::gapi::own::Mat& mat)
void createMat(const cv::GMatDesc &desc, cv::gapi::own::Mat& mat)
{
const auto type = desc.planar ? desc.depth : CV_MAKETYPE(desc.depth, desc.chan);
const auto size = desc.planar ? cv::gapi::own::Size{desc.size.width, desc.size.height*desc.chan}
: desc.size;
mat.create(size, type);
// FIXME: Refactor (probably start supporting N-Dimensional blobs natively
if (desc.dims.empty())
{
const auto type = desc.planar ? desc.depth : CV_MAKETYPE(desc.depth, desc.chan);
const auto size = desc.planar ? cv::gapi::own::Size{desc.size.width, desc.size.height*desc.chan}
: desc.size;
mat.create(size, type);
}
else
{
GAPI_Assert(!desc.planar);
mat.create(desc.dims, desc.depth);
}
}
#if !defined(GAPI_STANDALONE)
void createMat(const cv::GMatDesc desc, cv::Mat& mat)
void createMat(const cv::GMatDesc &desc, cv::Mat& mat)
{
const auto type = desc.planar ? desc.depth : CV_MAKETYPE(desc.depth, desc.chan);
const auto size = desc.planar ? cv::Size{desc.size.width, desc.size.height*desc.chan}
: cv::gapi::own::to_ocv(desc.size);
mat.create(size, type);
// FIXME: Refactor (probably start supporting N-Dimensional blobs natively
if (desc.dims.empty())
{
const auto type = desc.planar ? desc.depth : CV_MAKETYPE(desc.depth, desc.chan);
const auto size = desc.planar ? cv::Size{desc.size.width, desc.size.height*desc.chan}
: cv::gapi::own::to_ocv(desc.size);
mat.create(size, type);
}
else
{
GAPI_Assert(!desc.planar);
mat.create(desc.dims, desc.depth);
}
}
#endif
+27
View File
@@ -0,0 +1,27 @@
// 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) 2018-2019 Intel Corporation
#include "precomp.hpp"
#include <functional> // hash
#include <numeric> // accumulate
#include <unordered_set>
#include <iterator>
#include <ade/util/algorithm.hpp>
#include <opencv2/gapi/infer.hpp>
cv::gapi::GNetPackage::GNetPackage(std::initializer_list<GNetParam> &&ii)
: networks(std::move(ii)) {
}
std::vector<cv::gapi::GBackend> cv::gapi::GNetPackage::backends() const {
std::unordered_set<cv::gapi::GBackend> unique_set;
for (const auto &nn : networks) unique_set.insert(nn.backend);
return std::vector<cv::gapi::GBackend>(unique_set.begin(), unique_set.end());
}
+22 -5
View File
@@ -6,6 +6,10 @@
#include "precomp.hpp"
#include <ade/util/iota_range.hpp>
#include <ade/util/algorithm.hpp>
#include <opencv2/gapi/opencv_includes.hpp>
#include <opencv2/gapi/own/mat.hpp> //gapi::own::Mat
#include <opencv2/gapi/gmat.hpp>
@@ -49,20 +53,31 @@ namespace{
#if !defined(GAPI_STANDALONE)
cv::GMatDesc cv::descr_of(const cv::Mat &mat)
{
return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
const auto mat_dims = mat.size.dims();
if (mat_dims == 2)
return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
std::vector<int> dims(mat_dims);
for (auto i : ade::util::iota(mat_dims)) {
// Note: cv::MatSize is not iterable
dims[i] = mat.size[i];
}
return GMatDesc{mat.depth(), std::move(dims)};
}
cv::GMatDesc cv::descr_of(const cv::UMat &mat)
{
GAPI_Assert(mat.size.dims() == 2);
return GMatDesc{ mat.depth(), mat.channels(),{ mat.cols, mat.rows } };
}
cv::GMetaArgs cv::descr_of(const std::vector<cv::Mat> &vec)
cv::GMetaArgs cv::descrs_of(const std::vector<cv::Mat> &vec)
{
return vec_descr_of(vec);
}
cv::GMetaArgs cv::descr_of(const std::vector<cv::UMat> &vec)
cv::GMetaArgs cv::descrs_of(const std::vector<cv::UMat> &vec)
{
return vec_descr_of(vec);
}
@@ -70,10 +85,12 @@ cv::GMetaArgs cv::descr_of(const std::vector<cv::UMat> &vec)
cv::GMatDesc cv::gapi::own::descr_of(const cv::gapi::own::Mat &mat)
{
return GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}};
return (mat.dims.empty())
? GMatDesc{mat.depth(), mat.channels(), {mat.cols, mat.rows}}
: GMatDesc{mat.depth(), mat.dims};
}
cv::GMetaArgs cv::gapi::own::descr_of(const std::vector<cv::gapi::own::Mat> &vec)
cv::GMetaArgs cv::gapi::own::descrs_of(const std::vector<cv::gapi::own::Mat> &vec)
{
return vec_descr_of(vec);
}