Skip to content

[GAPI] Support basic inference in OAK backend#21504

Merged
alalek merged 2 commits intoopencv:4.xfrom
smirnov-alexey:as/oak_infer
Apr 5, 2022
Merged

[GAPI] Support basic inference in OAK backend#21504
alalek merged 2 commits intoopencv:4.xfrom
smirnov-alexey:as/oak_infer

Conversation

@smirnov-alexey
Copy link
Copy Markdown
Contributor

@smirnov-alexey smirnov-alexey commented Jan 24, 2022

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2021.4.2:20.04
build_image:Custom Win=openvino-2021.4.2
build_image:Custom Mac=openvino-2021.4.2

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

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

This PR brings several new features in OAK backend:

  • Camera config
    • Introduced rather basic config for the user to provide for ColorCamera. Note, that it still doesn't support all of the DAI parameters, e.g. resolutions
  • Inference support
    • Added support for infer() operation via a kernel in OAK backend. Currently it only accepts GFrame as input - not sure if other types are applicable since the stream comes from the camera. Meta information is extracted from the DAI library. Preprocessing is currently tied to camera - this will be refactored separately and done as an additional node before the infer kernel (hidden from the user).
  • Additional heterogeneity support for the backend
    • Possible via Copy operation in the backend. It allows not to split OAK island in two when we want an original stream from the camera or any other node in the island. Copy can be graph's output, passthrough operation (connects two nodes in the island) or both - the behavior in those cases is different (described and implemented in the backend).
  • 2 samples
    • Basic sample where we get stream from camera (wasn't possible before) via Copy
    • Infer sample with rendering

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@TolyaTalamanov @dmatveev @rgarnov fyi. This is just a basic proposal, so there are several major problems with the current design.

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

Note: nn metadata can be extracted from DAI once the feature is enabled there: luxonis/depthai-core#368

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@TolyaTalamanov @rgarnov please, review

@smirnov-alexey smirnov-alexey changed the title [WIP] [GAPI] Support basic inference in OAK backend [GAPI] Support basic inference in OAK backend Mar 10, 2022
@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

smirnov-alexey commented Mar 10, 2022

Note:

  1. There are some accuracy issues with the infer (could be model, could be our side - I will double check as a separate task/PR)
  2. Infer API is hard-coded now (GFrame as a single input, GMat as a single output). This will also be considered a separate task/PR (probably along with other infers (ROI, List, etc))
  3. Copy and infer are rather bad-designed currently but hopefully it will be resolved during code review

Copy link
Copy Markdown
Contributor

@rgarnov rgarnov left a comment

Choose a reason for hiding this comment

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

Just a few questions for now, will add more on goakbackend.cpp later

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@rgarnov please, take a look

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

@alalek can we merge this, please?

@dmatveev dmatveev self-assigned this Apr 1, 2022
@dmatveev dmatveev added this to the 4.6.0 milestone Apr 1, 2022
Copy link
Copy Markdown
Contributor

@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.

Looks ok, but please bear in mind I didn't dive deep into the backend code.

Just a simple question

  1. Is there any tests we could run with OAK connected?
  2. What happens on this:
    cv::GFrame in;
    cv::GFrame copy = cv::gapi::oak::copy(cv::gapi::oak::copy(cv::gapi::oak::copy(in)));
    cv::GFrame render = cv::gapi::renderFrame(copy, ...);
    cv::GMat out = cv::gapi::streaming::BGR(cv::gapi::oak::copy(render));
    As a user, I am able to write code like this and from the general G-API concept it is perfectly legal. What will happen here at graph compile time? At graph execution time?


@param model Path to model (.blob file)
*/
Params(const std::string &model) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be explicit

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

* which is specific to OAK models.
*/
struct ParamDesc {
std::string blob_file;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No input/output layer names here? How is this supposed to work? So far you test with 1-in 1-out models only?

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.

Currently only 1-in 1-out models are supported. Will extend once supported. Although, not sure if this info will be needed from the user since we extract all meta information from the model directly and utilize in the backend

Comment on lines +92 to +96
G_API_OP(GCopy, <GFrame(GFrame)>, "org.opencv.oak.copy") {
static GFrameDesc outMeta(const GFrameDesc& in) {
return in;
}
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Right, this can be refactored. But for now I'd keep Copy as a separate operation in the backend

"{ detector | | Path to compiled .blob face detector model }"
"{ duration | 1 | Number of frames to pull from camera and run inference on }";

#ifdef HAVE_OAK
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if this #ifdef at a right place, considering you including oak.hpp explicitly above.

If code compiles with NO OAK but WITH those headers included, do we need it here at all?

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.

Removed


// Initialize graph structure
cv::GFrame in;
cv::GFrame copy = cv::gapi::oak::copy(in); // NV12 transfered to host + passthrough copy for infer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe this copy should be isp if we want to trick that it is camera

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.

Didn't get the idea, could you explain in more details, please?

Comment on lines +127 to +130
int main() {
GAPI_Assert(false && "Built without OAK support");
return -1;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the app code above can compile with no OAK present, I believe we don't need this either

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.

Removed

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

Will address open comments in a separate PR. @alalek can we merge this one, please?

@smirnov-alexey
Copy link
Copy Markdown
Contributor Author

smirnov-alexey commented Apr 5, 2022

@dmatveev answering your questions above:

  1. There is a simple test in opencv_test_gapi under HAVE_OAK guard which checks that the backend compiles
  2. There is a check with a meaningful error message that there are no back-to-back copy operations in the backend. Also it checks that there is only 1 OAK island in graph

@alalek alalek merged commit 7ed5574 into opencv:4.x Apr 5, 2022
@opencv-pushbot opencv-pushbot mentioned this pull request Apr 23, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
[GAPI] Support basic inference in OAK backend

* Combined commit which enables basic inference and other extra capabilities of OAK backend

* Remove unnecessary target options from the cmakelist
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.

4 participants