Skip to content

features2d: reduce accuracy test avg memory consumption#25424

Merged
asmorkalov merged 4 commits intoopencv:4.xfrom
mshabunin:fix-features2d-test
Apr 17, 2024
Merged

features2d: reduce accuracy test avg memory consumption#25424
asmorkalov merged 4 commits intoopencv:4.xfrom
mshabunin:fix-features2d-test

Conversation

@mshabunin
Copy link
Copy Markdown
Contributor

@mshabunin mshabunin commented Apr 16, 2024

Merge with contrib: opencv/opencv_contrib#3722

I've observed high memory consumption in the opencv_test_features2d (x86_64, Ubuntu 22.04, Debug):

image
It's always more than 180 MiB with peak at 535 MiB

This was caused by pointers to the algorithm object instances stored in the tests parameters. I've replaced them with factory functions/lambdas with the following result:

image
Now peak is at 355 MiB and permanent consumption level is ~ 1-2 MiB

Note: current peak is caused by KAZE features allocating 8x image size utility buffers. Not sure if we can or should do anything about it:

aux.Lx = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.Ly = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.Lxx = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.Lxy = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.Lyy = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.Lt = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.Lsmooth = Mat::zeros(options_.img_height, options_.img_width, CV_32F);
aux.Ldet = Mat::zeros(options_.img_height, options_.img_width, CV_32F);

@mshabunin
Copy link
Copy Markdown
Contributor Author

Apparently xfeatures2d tests directly use features2d test, so that has to be fixed too: opencv/opencv_contrib#3722

"../stitching/a3.png", \
"../stitching/s2.jpg")

PARAM_TEST_CASE(Feature2DFixture, Ptr<Feature2D>, std::string)
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 got the idea, to make detector initialization lazy and move it from GTest cases generator inside the test body. I propose to add comment with the solution description. Without the memory consumption knowledge the test design looks very strange and ambiguous.


#define SHOW_DEBUG_LOG 1

typedef tuple<std::string, Ptr<FeatureDetector>, Ptr<DescriptorExtractor>, float>
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.

Please add comment with design decision here too.

@asmorkalov asmorkalov self-assigned this Apr 17, 2024
@asmorkalov asmorkalov added this to the 4.10.0 milestone Apr 17, 2024
@asmorkalov asmorkalov merged commit f9e9567 into opencv:4.x Apr 17, 2024
@mshabunin mshabunin deleted the fix-features2d-test branch April 17, 2024 17:25
@asmorkalov asmorkalov mentioned this pull request Apr 19, 2024
klatism pushed a commit to klatism/opencv that referenced this pull request May 17, 2024
features2d: reduce accuracy test avg memory consumption opencv#25424

**Merge with contrib**: opencv/opencv_contrib#3722

I've observed high memory consumption in the `opencv_test_features2d` (x86_64, Ubuntu 22.04, Debug):

![image](https://github.com/opencv/opencv/assets/3304494/419d65d9-d727-4d1e-bdec-dbde6681c188)
It's always more than 180 MiB with peak at 535 MiB

This was caused by pointers to the algorithm object instances stored in the tests parameters. I've replaced them with factory functions/lambdas with the following result:

![image](https://github.com/opencv/opencv/assets/3304494/bd4ff0ea-3db4-4ab8-8e6d-192a3826e99c)
Now peak is at 355 MiB and permanent consumption level is ~ 1-2 MiB


**Note:** current peak is caused by KAZE features allocating 8x image size utility buffers. Not sure if we can or should do anything about it: https://github.com/opencv/opencv/blob/66fb5021e9253e3decab376d00322eaf2b279c89/modules/features2d/src/kaze/KAZEFeatures.cpp#L61-L68
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.

2 participants