Skip to content

Fix resize+concat optimization#20647

Merged
alalek merged 2 commits intoopencv:3.4from
rogday:resize_concat_optimization
Sep 3, 2021
Merged

Fix resize+concat optimization#20647
alalek merged 2 commits intoopencv:3.4from
rogday:resize_concat_optimization

Conversation

@rogday
Copy link
Copy Markdown
Member

@rogday rogday commented Sep 2, 2021

Merge with extra: opencv/opencv_extra#905

Fixes #17726
relates #11050 (code branch has zero coverage)

The results of nets start diverging after(including) 'decoder/concat' Concat layer. I tracked it down to dnn.cpp:2962, where the optimization of this layer is applied: it disables 'decoder/concat' layer and changes the output mats of input layers of type ResizeBilinear to point to different parts of the one big matrix. The problem is in 'decoder/ResizeBilinear_1': it effectively does nothing since its input is already has 64x64 WxH, and so it just returns, doing nothing. But if the optimization was applied, input and output matrices differ and a copy should be performed.

opencv_extra=resize_concat_optimization

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

Comment on lines +113 to +118
if (outHeight == inputs[0].size[2] && outWidth == inputs[0].size[3])
{
if (inputs[0].data != outputs[0].data)
{
inputs[0].copyTo(outputs[0]);
}
Copy link
Copy Markdown
Member

@alalek alalek Sep 2, 2021

Choose a reason for hiding this comment

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

Thank you for the fix!

  1. Please fix indentation (4 spaces)
  2. Please add comment that: Zero copy outputs[0] = inputs[0] + outputs_arr.assign() doesn't work due to BlobManager (doesn't respect real refcounts from Mat).

@alalek alalek merged commit d0e612d into opencv:3.4 Sep 3, 2021
@alalek alalek mentioned this pull request Sep 11, 2021
@rogday rogday deleted the resize_concat_optimization branch October 7, 2021 13:15
@alalek alalek mentioned this pull request Oct 15, 2021
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