Skip to content

[G-API]: Performance tests for BackgroundSubtractor#19542

Merged
alalek merged 7 commits intoopencv:masterfrom
OrestChura:oc/BGSub_ptest
Mar 10, 2021
Merged

[G-API]: Performance tests for BackgroundSubtractor#19542
alalek merged 7 commits intoopencv:masterfrom
OrestChura:oc/BGSub_ptest

Conversation

@OrestChura
Copy link
Copy Markdown
Contributor

@OrestChura OrestChura commented Feb 16, 2021

  • Performance tests for BackgroundSubtractor stateful operation added
  • Accuracy test misprint fixed

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
force_builders=Custom
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

build_image:Custom=centos:7
buildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

xbuild_image:Custom=ubuntu-openvino-2021.1.0:20.04
xbuild_image:Custom Win=openvino-2021.1.0
xbuild_image:Custom Mac=openvino-2021.1.0

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

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

@OrestChura
Copy link
Copy Markdown
Contributor Author

@anna-khakimova please review

Copy link
Copy Markdown
Contributor

@mpashchenkov mpashchenkov left a comment

Choose a reason for hiding this comment

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

First wave.

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Please take a look on existed OpenCV performance tests for this functionality first.

Comment on lines +208 to +215
// Processing `testNumFrames` amount of frames without measurements:
while (frames++ <= testNumFrames && cap.grab())
{
cap.retrieve(frame);
c.apply(frame, gapiForeground);
pOCVBackSub->apply(frame, ocvForeground, learningRate);
EXPECT_TRUE(cmpF(gapiForeground, ocvForeground));
}
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.

Accuracy checks must be removed from the performance tests. Use accuracy tests for that.

"OCV" code must gone from all perf tests.

Copy link
Copy Markdown
Contributor Author

@OrestChura OrestChura Feb 23, 2021

Choose a reason for hiding this comment

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

Yes, a lot of comparison was excess; comparison was removed from the cycle.
However, by design of G-API performance tests, it is necessary to be sure the kernel is working properly while measuring the performance.
It's really not my call to change it in this PR.
I left a single comparison for the validation.

// ...and then measuring the G-API subtractor performance on the single frame
TEST_CYCLE()
{
c.apply(frame, gapiForeground);
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.

Is c stateless?

  • if yes, the just 1 frame is not enough (code measures "initialization" code which doesn't make sense)
  • if no, then it is just wrong. Performance samples must measure the same code.

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.

You are right, thanks! The measuring was refactored and now a performance of the kernel on a sequence of the same n frames (with resetting the state between iterations) is measured.

@anna-khakimova
Copy link
Copy Markdown
Member

anna-khakimova commented Feb 25, 2021

Looks good for me.

frames.push_back(frame);
}
}
testNumFrames = frames.size();
Copy link
Copy Markdown
Contributor

@mpashchenkov mpashchenkov Feb 26, 2021

Choose a reason for hiding this comment

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

Another change of value, it is curiously. testNumFrames = warm_up_frames + perf_test_work_frames, is it?

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.

This line is to avoid termination in case the video has less frames than it was required. So at this point testNumFrames is the real number of frames read

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.

This variable independent of test parameter. What if read() returns false (some problem) and we receive part of frames? Is it correct behavior for this case?

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.

Yes, exactly, this line handles the case when, for example, a video is too short and there are not enough frames. If so, I decided that the expected behaviour would be to process the obtainable amount of frames.

In the case when everything is all right the variable wouldn't change

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 hope "everything isn't right" case doesn't relate to this test and this step is just in case.

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.

What if frames.size() is zero?

Copy link
Copy Markdown
Contributor Author

@OrestChura OrestChura Mar 2, 2021

Choose a reason for hiding this comment

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

Yes, absolutely, this step is just in case.

If size is 0.. it's extremely unlikely, as video should have no frames despite the fact it have been read successfully.
But if it actually happened, nothing would be processed, so output Mats would remain empty. And then validation either would or would not pass. Which is not the expected behaviour

I'll add assert to have speakable error

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.

Assertion check must be here.

We can't have "flexible" scope for performance sampling. Test code must be fixed instead if error occurs.

Copy link
Copy Markdown
Contributor Author

@OrestChura OrestChura Mar 2, 2021

Choose a reason for hiding this comment

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

I see. Added termination in case frames.size() is not testNumFrames after reading instead of re-assignment

@OrestChura
Copy link
Copy Markdown
Contributor Author

@alalek Are the Jenkins builds important to be green for merging?
If yes, could you please retry them? They seem just to not have been able to fetch OpenCV for some reasons last time

@alalek
Copy link
Copy Markdown
Member

alalek commented Mar 3, 2021

Jenkins builders are optional for now (there are several infrastructure issues not related to any patch)

@OrestChura
Copy link
Copy Markdown
Contributor Author

@alalek please check if this is mergeable

@OrestChura OrestChura requested a review from alalek March 9, 2021 13:51
@alalek alalek merged commit c1a57a1 into opencv:master Mar 10, 2021
@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]: Performance tests for BackgroundSubtractor

* Perf.Tests for BackgroundSubtractor kernel

* Fix CI

* Addressing comments

* Addressing a comment

* Test cycle and validation changes

* Addressing  comment

* Added assert
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