Skip to content

[Fix] DDRNet: fix tensor size mismatch on non-standard input resolutions#3876

Open
Selig209 wants to merge 1 commit intoopen-mmlab:dev-1.xfrom
Selig209:fix/ddrnet-resize-mismatch
Open

[Fix] DDRNet: fix tensor size mismatch on non-standard input resolutions#3876
Selig209 wants to merge 1 commit intoopen-mmlab:dev-1.xfrom
Selig209:fix/ddrnet-resize-mismatch

Conversation

@Selig209
Copy link
Copy Markdown

When using DDRNet with input dimensions that don't divide evenly by 8 (e.g. after keep_ratio=True resizing), the forward pass crashes with:

RuntimeError: The size of tensor a (182) must match the size of tensor b (181) at non-singleton dimension 3

The issue is that out_size is 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. When comp_c gets resized to out_size and added to x_s, the shapes don't match.

Moved out_size to be computed from the actual tensor shape after the stem, so the resize target always matches x_s.

Fixes #3347

Copilot AI review requested due to automatic review settings April 25, 2026 23:52
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 25, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_size from x.shape[-2:] after self.stem(x) to ensure all subsequent resize(..., 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:]

Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants