Skip to content

G-API: Support GFrame for ONNX infer #19070

Merged
alalek merged 8 commits intoopencv:masterfrom
mpashchenkov:mp/onnx-gframe
Dec 24, 2020
Merged

G-API: Support GFrame for ONNX infer #19070
alalek merged 8 commits intoopencv:masterfrom
mpashchenkov:mp/onnx-gframe

Conversation

@mpashchenkov
Copy link
Copy Markdown
Contributor

@mpashchenkov mpashchenkov commented Dec 10, 2020

Support cv::MediaFrame for infer input in ONNX backend.

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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

Custom build:

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-onnx:20.04
build_image:Custom Win=ubuntu-onnx:20.04
build_image:Custom Mac=ubuntu-onnx:20.04

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

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@mpashchenkov
Copy link
Copy Markdown
Contributor Author

@smirnov-alexey, please review.

@smirnov-alexey
Copy link
Copy Markdown
Contributor

@mpashchenkov please extend builds section (can take from here #19009 I believe)

break;
}
case cv::GMetaArg::index_of<cv::GFrameDesc>(): {
// FIXME: Is there any validation for GFrame ?
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.

Maybe you need to check color formats here? If there are similar cases with no checks for GFrameDesc lets just left this as is

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.

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.

Is it done?

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.

Added check for GFrameDesc parameters. I think it should be a function (analogue of isND()) because IE backend should do similar checks. Create a ticket for this?

@smirnov-alexey
Copy link
Copy Markdown
Contributor

Overall looks good, thanks!

@mpashchenkov
Copy link
Copy Markdown
Contributor Author

@TolyaTalamanov, @dmatveev, it is.

}
}

void preprocess(const std::unique_ptr<cv::MediaFrame::View>& view,
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.

It can be just View& as for giebackend

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.

Fixed.

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.

I think it can be merged

switch (ctx.in_shapes[in_idx]) {
case cv::GShape::GFRAME: {
const cv::MediaFrame& frame = ctx.inFrame(in_idx);
views.emplace_back(new cv::MediaFrame::View(frame.access(cv::MediaFrame::Access::R)));
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.

Make sure your views is preallocated to the right size.

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.

Added assert.

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.

it should be a reserve() somewhere earlier in the stack.

the idea is to avoid vector reallocations if possible, but since elements will be moved instead of copied, it should still work for unique pointers over views.

break;
}
case cv::GMetaArg::index_of<cv::GFrameDesc>(): {
// FIXME: Is there any validation for GFrame ?
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.

Is it done?

@dmatveev
Copy link
Copy Markdown
Contributor

@mpashchenkov is it ready for review?

switch (ctx.in_shapes[in_idx]) {
case cv::GShape::GFRAME: {
const cv::MediaFrame& frame = ctx.inFrame(in_idx);
views.emplace_back(new cv::MediaFrame::View(frame.access(cv::MediaFrame::Access::R)));
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.

it should be a reserve() somewhere earlier in the stack.

the idea is to avoid vector reallocations if possible, but since elements will be moved instead of copied, it should still work for unique pointers over views.

break;
}
case cv::GShape::GMAT: {
exMat = ctx.inMat(in_idx);
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.

It also requires preprocessing, isn't it?

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.

...resize, normalization, etc. Where does it happen now for a regular GMat input?

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.

oh I see you do it also in setInput(). This flow is somewhat complicated, do you have two preprocess() functions now which do different things?

@dmatveev dmatveev added this to the 4.5.2 milestone Dec 24, 2020
@dmatveev dmatveev self-assigned this Dec 24, 2020
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.

Let's merge it now as it seem to work, but file a refactoring task to our tracker.

What is confusing here now is calling void extractMat(...) first and then accessing some .exMat field. This needs to be reworked to make side effects more clear.

@alalek alalek merged commit 656b20a into opencv:master Dec 24, 2020
@alalek alalek mentioned this pull request Apr 9, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
G-API: Support GFrame for ONNX infer 

* Added GFrame for ONNX

* Cut test

* Removed IE from assert

* Review comments

* Added const/bbot rstrt

* View instead unique_ptr in func. sig.

* Added extractMat function, ONNXCompiled contains exMat - cv::Mat with non processed input data

* Added meta check for inferList2
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.

5 participants