Skip to content

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

Merged
alalek merged 4 commits intoopencv:masterfrom
dmatveev:dm/ng-0001-g-api-inference-api
Aug 5, 2019
Merged

G-API-NG/API: Introduced inference API and IE-based backend#15090
alalek merged 4 commits intoopencv:masterfrom
dmatveev:dm/ng-0001-g-api-inference-api

Conversation

@dmatveev
Copy link
Copy Markdown
Contributor

@dmatveev dmatveev commented Jul 18, 2019

Inference in G-API

This PR introduces basic inference support to G-API.

Changes overview

Core G-API

  • own::Mat has been extended with N-dimensions support. Continues
    mimicing to cv::Mat in this behavior. Added tests.
  • GMatDesc now also supports dimensions in addition to a regular 2D
    size. A new constructor has been added to.
  • cv::descr_of() overload for vector of Mats has been renamed to
    cv::descrs_of() (and I am still wondering if we actually need this
    function). A vector of Mats now is a valid host form for GArray<GMat>.
  • Operations are extended with tags. By default, all our old regular
    kernels have empty tags (and are identified solely by kernel ID).
  • Engine has been extended with backend-defined metadata resolution
    callbacks (see below).

On backend-specific outMeta

In our regular interface, an outMeta (defining formats operations's
of outputs given the inputs) is defined with the operation itself --
so it describes API contract and not a particular implementation.

Sometimes an operation can't fully describe its meta when it is
defined, and so backends can put their own methods to the graph once
there's a clarity.

Example: when we define a network as API entry, we're not certain
about its input/output formats (data type, dimensions, etc) until we
actually load the network. This loading happens on graph compilation
stage, not on the graph construction stage, and is defined by the
underlying engines which do the actual work.

New entities

Inference API

Inference API is represented by just two files:

  • include/opencv2/gapi/infer.hpp
  • src/api/ginfer.cpp

Header file is the most importand one, it defines two generic
operations: Infer and InferList, and an API to express networks we
use (G_API_NET() macro).

Once a user declares his network, it can be used to construct graphs.
Network's name (a macro parameter) is used as an operation tag (see
above) to distinguish between different infer calls in graph (note -
the operation itself is always the same).

Similar to kernels, scoring engines are specified in the form of
backend-specific network parameters which are then passed to G-API
as compilation arguments (as a Network package).

Since every inference backend's parameters may differ, but network
parameters are also tightly coupled with networks itselves,
backend-specific parameters are usually derivatives from the network
APIs. Networks (as types) are specified as template arguments to
universal backend-specific parameter structures so knowledge about
network and its backend combines in a single object.

A code is worth a thousand words so please review a test in this PR.

Inference backend (DLDT)

The above API is (as usual) just an interface which can be implemented
(multiple times). This PR introduces a basic DLDT/IE-based
implementation of the inference interface.

This backend implements the two universal inference kernels (Infer
and InferList) and provies a configuration API (see
gapi/infer/ie.hpp). It already supports automatic preprocessing with
Crop/Scale/CSC pipeline out-of-the-box. And yes, in this case G-API is
working from within a G-API. :)

Tests

So far tested with a DLDT Age/Gender model only. Model is taken from
DNN module's own test suite.

force_builders=Custom,Custom Win,Custom Mac
build_image:Custom=ubuntu-openvino-2019r2.0:16.04
build_image:Custom Win=openvino-2019r1
build_image:Custom Mac=openvino-2019r1

test_modules:Custom=gapi
test_modules:Custom Win=gapi
test_modules:Custom Mac=gapi

buildworker:Custom=linux-1
test_opencl:Custom=ON
test_bigdata:Custom=1
test_filter:Custom=*

build_gapi_standalone:Linux x64=ade-0.1.1d
build_gapi_standalone:Win64=ade-0.1.1d
build_gapi_standalone:Mac=ade-0.1.1d
build_gapi_standalone:Linux x64 Debug=ade-0.1.1d

Copy link
Copy Markdown
Contributor Author

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

19 new FIXMEs introduced, needs to be reduced

@dmatveev
Copy link
Copy Markdown
Contributor Author

@alalek thanks for the magic script :)

Copy link
Copy Markdown
Contributor Author

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few-more self-comments

@dmatveev dmatveev force-pushed the dm/ng-0001-g-api-inference-api branch 2 times, most recently from 69a70f4 to ba6c699 Compare July 22, 2019 23:26
@dmatveev dmatveev requested review from AsyaPronina and dkurt July 23, 2019 13:08
@dmatveev
Copy link
Copy Markdown
Contributor Author

@dkurt @AsyaPronina @rgarnov @andrey-golubev can you please have a look?

Copy link
Copy Markdown
Member

@andrey-golubev andrey-golubev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, I'd suggest to make minor changes in some places

} // namespace detail

// Note: descr_of(std::vector<..>) returns a GArrayDesc, while
// descrs_of(std::vector<..>) returns an array of Meta args!
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds confusing. May be descr_of and metas_of/meta_args_of are better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if IE is not using it and I will delete it at all.

Copy link
Copy Markdown
Member

@andrey-golubev andrey-golubev Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in IE

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will rename to metas_of if any new change to this PR will be requested.

@dmatveev dmatveev force-pushed the dm/ng-0001-g-api-inference-api branch from 960697a to 08949dd Compare July 25, 2019 23:31
@dmatveev
Copy link
Copy Markdown
Contributor Author

@andrey-golubev addressed the majority if your comments, thanks a lot for such a torough review!

@alalek builds seem to be green (except ABI change which was intentional - to fix a problem), I believe this can be merged when time permits and things become safe to merge (post-4.1.1)

Copy link
Copy Markdown
Member

@andrey-golubev andrey-golubev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@dmatveev
Copy link
Copy Markdown
Contributor Author

@alalek do we wait for anything else to merge?


const std::string path = "Retail/object_attributes/age_gender/dldt/age-gender-recognition-retail-0013";
const auto topology_path = findDataFile(path + ".xml");
const auto weights_path = findDataFile(path + ".bin");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use false with second parameter for findDataFile() (for files which are not from opencv_extra)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

- Very quick-n-dirty implementation
- OpenCV's own DNN module is not used
- No tests so far
- 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
- Pass `false` to findDataFile()
- Add deprecation warning suppression macros for IE
@dmatveev dmatveev force-pushed the dm/ng-0001-g-api-inference-api branch from 014d18b to d405ad1 Compare August 3, 2019 10:16
@dmatveev
Copy link
Copy Markdown
Contributor Author

dmatveev commented Aug 5, 2019

@alalek anything else?

@alalek alalek merged commit 0757a51 into opencv:master Aug 5, 2019
@dmatveev
Copy link
Copy Markdown
Contributor Author

dmatveev commented Aug 6, 2019

🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 🍾 THanks!

a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…nce-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants