Fix detach_sample dropping channels of multi-channel views#457
Merged
Conversation
detach_sample computed a single n_channels from the first view (source) and applied it to all views. For virtual staining where source is 1 channel but target/pred are 2 channels (nucleus + membrane), the second channel was silently dropped, so TensorBoard sample grids showed only one fluorescence channel. Loop over each view's own channel count instead. Add a regression test and update the docstring to cover views with differing channel counts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes viscy_utils.log_images.detach_sample so image-grid logging preserves all channels for each view (instead of using the first view’s channel count for all views), preventing silent channel drops in virtual staining logs.
Changes:
- Update
detach_sampleto iterate over each view’s own channel count when building per-sample grid rows. - Add a regression test covering mixed channel counts across views (e.g., source=1ch, target/pred=2ch) and validate the rendered grid shape.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/viscy-utils/src/viscy_utils/log_images.py |
Fix per-view channel iteration so multi-channel views aren’t truncated during logging. |
packages/viscy-utils/src/viscy_utils/log_images_test.py |
Adds regression tests for mixed-channel view logging and rendered grid sizing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The regression test was under src/viscy_utils/, which the repo-wide pytest testpaths (packages/*/tests, applications/*/tests) does not collect, so it would not run in CI. Move it to packages/viscy-utils/tests/test_log_images.py. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
srivarra
approved these changes
Jun 5, 2026
ieivanov
added a commit
that referenced
this pull request
Jun 12, 2026
Resolve conflicts from main's monorepo re-staging: - Keep branch's unified rotation_tta_transforms TTA in cytoland engine; drop main's superseded square-padding helpers, graft in main's n<1 guard. - Take main elsewhere: _read_norm_meta rename (+public alias), qc->viscy-qc package rename, log_images multi-channel-view fix (#457), docs/READMEs, moved svideo_1.png. Regenerate uv.lock. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
detach_sample(inviscy-utils) computed a singlen_channelsfrom the first view and applied it to all views. For virtual staining wheresourceis 1 channel buttarget/predare 2 channels (nucleus + membrane), the second channel was silently dropped — so TensorBoardtrain_samples/val_samplesgrids showed only one fluorescence channel instead of both.This is the logging path used by
cytoland.engine.VSUNet(anddynacell), which is what theimage_translationcourse exercise exercises.Root cause
Introduced in the monorepo refactor (#373); the pre-split
detach_samplekept each view's own channels.Fix
Loop over each view's own channel count (
range(patch.shape[0])). Views with differing channel counts are all logged in full.Verification
log_images_test.py: phase2fluor shapes (source 1ch, target/pred 2ch) now produce 5 columns per row (1 + 2 + 2); rendered grid is(192, 320, 3).uv run pytest packages/viscy-utils/src/viscy_utils/log_images_test.pypasses.🤖 Generated with Claude Code