-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
G-API: Provide API to configure IE backend. #22522
Copy link
Copy link
Open
Labels
Description
Design proposal
Introduction
OpenVINO provides API for specifying input/output nn model characteristics such as: Precision, Layout, particularly for input it's also possible to specify if some preprocessing should be applied. This characteristics are individual per input or output and configurable via: IE::Data.
Motivation
To make user's life easier G-API configure OpenVINO with following behavior:
Precisionfor every input layer set automatically to type that came as graph input meta. https://github.com/opencv/opencv/blob/4.x/modules/gapi/src/backends/ie/giebackend.cpp#L1076Layoutfor every input layer calculated based on this:
2.1 Check if input eitherIMAGEorTENSOR:
https://github.com/opencv/opencv/blob/4.x/modules/gapi/src/backends/ie/giebackend.cpp#L138
2.2 In caseIMAGEit will be alwaysNHWC.
2.3 In caseTENSORit will be decided based on number of dims: https://github.com/opencv/opencv/blob/4.x/modules/gapi/src/backends/ie/giebackend.cpp#L96- Output
Precision/Layoutis impossible to configure at all. They're left by default.
Based on this behavior there are several flaws:
- Multi-dim (dim == 4)
cv::Matis always treated asNCHWand there is no any chance to specifyNHWCinstead. - Multi-dim (dim == 2)
cv::Matis always treated asNCand there is no any chance to specifyHWinstead. Precision/Layoutfor output layers impossible to configure. It might slightly improve performance if user let's say wanna receiveFP16output data without conversion performed onOpenVINOside.
Proposal
Actually proposal is simple, introduce following handles inside cv::gapi::ie::Params structure:
API Example:
cv::gapi::ie::Params(...).cfgInputLayout('input0', 'NCHW')
.cfgOutputPrecision('output0', 'FP16')
.cfgOutputLayout('output0', 'NCHW')
.cfgOutputPrecision('output1', 'FP16')
.cfgOutputLayout('output1', 'NCHW')
Another idea is use CV_* enums to specify precision:
cv::gapi::ie::Params(...).cfgOutputPrecision(CV_16F) // set all output layers precision to ie::FP16
I'd suggest using string as type for Layout (probably for Precision)
- OV2.0 uses strings: https://docs.openvino.ai/latest/openvino_docs_OV_UG_Layout_Overview.html
- It doesn't require extra
enum's onG-APIside. - Easy adopt to python
Reactions are currently unavailable