Skip to content

Fix output channel calculation in PixelShuffle2DUpBlock - #40

Open
wli51 wants to merge 4 commits into
WayScience:mainfrom
wli51:upsample-fix
Open

Fix output channel calculation in PixelShuffle2DUpBlock #40
wli51 wants to merge 4 commits into
WayScience:mainfrom
wli51:upsample-fix

Conversation

@wli51

@wli51 wli51 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Older behavior is erroneous behavior from previous refactor due to lack of caution.

With pixel shuffle up sampling, the channel should reduce proportional to the combined 2D spatial expansion as opposed to remaining identical:

# Conceptually reasonable upsampling via pixel shuffling:
C × H × W
   ↓ Conv: C → C
C × H × W
   ↓ PixelShuffle(2)
C/4 × 2H × 2W # information is moved from channel to result in 4x increase in pixel along H&W, so channel loses 4x

# Earlier implementation
C × H × W
   ↓ Conv: C → 4C
4C × H × W
   ↓ PixelShuffle(2)
C × 2H × 2W # C remains unchanged despite pixels are shuffled from C into H&W, 
# because the pixel shuffle operation is itself rigid, this implementation effectively forces the conv2d layers bundled in
# `PixelShuffle` to invent 4x information. 
# Although this boosts model capacity because there are extra learnable parameters I prefer to have no  

wli51 added 4 commits August 19, 2026 16:22
…r spatial downsample factor. Erroenous behavior from previous refactor due to lack of caution. With pixel shuffle upsampling, the channel should reduce proportional to the combined 2D sptial expansion as opposed to remaining identical. This also fixes the problem of older (up to v0.7) model loading.
… channel perserving and unpreserving behavior for maximized backward compatibility. The default behavior for unext initialization is channel non-preserving which is the more reasonable yet lower capacity version.
…proved configuration handling and backward compatibility
…ut_h and out_w only works for a specific directional of sampling against a very specific block type.

Copilot AI left a comment

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.

Pull request overview

Corrects PixelShuffle upsampling channel sizing while adding an opt-in legacy preservation mode.

Changes:

  • Reduces output channels proportionally to 2D expansion.
  • Adds channel-preservation configuration.
  • Updates stage calculations and tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Summary
tests/models/test_up_down_blocks.py Tests reduced and preserved channel behavior.
src/virtual_stain_flow/models/unext.py Wires and serializes channel preservation; missing-key fallback may break loading older checkpoints.
src/virtual_stain_flow/models/stages.py Updates stage spatial-dimension calculations.
src/virtual_stain_flow/models/blocks/up_down_blocks.py Implements proportional PixelShuffle channel reduction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

init_cfg = config.get("init", config)
if "_pixel_shuffle_preserve_channels" not in init_cfg:
# For backward compatibility with configs that don't have this key
init_cfg["_pixel_shuffle_preserve_channels"] = False
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.

2 participants