[Fix] DDRNet: fix tensor size mismatch on non-standard input resolutions#3876
Open
Selig209 wants to merge 1 commit intoopen-mmlab:dev-1.xfrom
Open
[Fix] DDRNet: fix tensor size mismatch on non-standard input resolutions#3876Selig209 wants to merge 1 commit intoopen-mmlab:dev-1.xfrom
Selig209 wants to merge 1 commit intoopen-mmlab:dev-1.xfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a DDRNet forward-pass crash on inputs whose spatial dimensions don’t divide evenly by 8 by computing the resize target from the post-stem tensor shape (rather than from raw input integer division), preventing off-by-one mismatches during feature fusion.
Changes:
- Compute
out_sizefromx.shape[-2:]afterself.stem(x)to ensure all subsequentresize(..., size=out_size)calls match the spatial branch resolution.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+187
to
+190
| # Use actual spatial dims after stem to avoid off-by-one errors | ||
| # when input resolution is not perfectly divisible by 8. | ||
| out_size = x.shape[-2:] | ||
|
|
There was a problem hiding this comment.
This bug fix isn’t covered by a regression test. Please add a unit test for DDRNet that feeds an input whose H/W aren’t divisible by 8 (e.g. 1025x1023 or a keep_ratio-like shape) and asserts the forward pass runs without error and that the feature maps being added/resized have matching spatial shapes.
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.
When using DDRNet with input dimensions that don't divide evenly by 8 (e.g. after
keep_ratio=Trueresizing), the forward pass crashes with:RuntimeError: The size of tensor a (182) must match the size of tensor b (181) at non-singleton dimension 3The issue is that
out_sizeis precomputed as(H // 8, W // 8)from the raw input, but the stem's strided convolutions can produce spatial dims that are off by one due to integer division rounding. Whencomp_cgets resized toout_sizeand added tox_s, the shapes don't match.Moved
out_sizeto be computed from the actual tensor shape after the stem, so the resize target always matchesx_s.Fixes #3347