save allocation of memory for fake image#19536
Merged
opencv-pushbot merged 1 commit intoopencv:3.4from Feb 22, 2021
WeiChungChang:ReduceMemory
Merged
save allocation of memory for fake image#19536opencv-pushbot merged 1 commit intoopencv:3.4from WeiChungChang:ReduceMemory
opencv-pushbot merged 1 commit intoopencv:3.4from
WeiChungChang:ReduceMemory
Conversation
asmorkalov
approved these changes
Feb 16, 2021
Contributor
asmorkalov
left a comment
There was a problem hiding this comment.
👍 Good catch! Thanks!
Member
|
This patch should go into 3.4 branch first. Please:
Note: no needs to re-open PR, apply changes "inplace". |
4 tasks
This was referenced Feb 23, 2021
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In ProposalLayerImpl layer, there is a fake image. For now, we actually allocate memory for it.
For example, if the input image has [N, C, H, W] = [1, 3, 1024, 1024], it will create a memory space of 1024*1024 = 1MB.
For edge devices, allocate 1MB unnecessary memory indeed consumes too much system resource.
Also notice that fakeImageBlob is a class member variable so its life scope is the same as dnn net.
However, this fake mat is used at:
In both of the layers, we don't access the content but merely request the shape info.
Instead, in the PR, we make fakeImageBlob as local variable. Also, it carries correct shape info but point to nulptr data(since it will NOT be used at all). So we can save, ex 1MB when doing inference for a model with ProposalLayer.
The figure below shows the result of memory usage probe (by valgrind --tool=massif) for ProposalLayerImpl fake image. in this case the input image is of [N, C, H, W] = [1, 3, 650, 650].
Originally the peak usage of memory is about 486.8 KB (650 * 650 ~ 422,5K plus alignment and other system memory ).
With this PR the peak usage of memory is only~ 72.04KB (only system memory ).
Notice that for HAVE_OPENCL, we may apply the same optimization also.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.