refactor(cytoland): unify VSUNet rotation TTA on rotation_tta_transforms - #451
refactor(cytoland): unify VSUNet rotation TTA on rotation_tta_transforms#451ieivanov wants to merge 1 commit into
Conversation
eb1ffa1 to
8f42e30
Compare
18fc247 to
dc8892d
Compare
|
Ed, Alex, this is optional, but I think nice to have. It unifies how |
There was a problem hiding this comment.
Pull request overview
This PR refactors Cytoland’s VSUNet.perform_test_time_augmentations (the viscy predict TTA path) to reuse the shared rotation_tta_transforms() helper, aligning it with the transform-list TTA implementation and fixing non-square FOV rotation behavior by removing square-padding rotation logic.
Changes:
- Switched
VSUNet.perform_test_time_augmentationsto userotation_tta_transforms()+_pad_forward_crop, and removed the bespoke square-pad rotation helpers. - Removed now-unused rotation-related state (
_original_shape_yx) andRotate90import. - Added a regression test to ensure non-square FOVs preserve YX shape under VSUNet rotation TTA for mean/median reductions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| applications/cytoland/src/cytoland/engine.py | Unifies VSUNet rotation TTA implementation on rotation_tta_transforms() and removes square-padding rotation helpers. |
| applications/cytoland/tests/test_engine.py | Adds regression coverage for VSUNet rotation TTA on non-square YX shapes. |
Comments suppressed due to low confidence (1)
applications/cytoland/src/cytoland/engine.py:491
perform_test_time_augmentationswill raiseUnboundLocalErrorifself.tta_typeis anything other than "mean"/"median"/"product" becausepredictionis never assigned in that case. Consider failing fast with a clearValueErrorso misconfiguration is easier to debug.
if self.tta_type == "mean":
prediction = torch.stack(predictions).mean(dim=0)
elif self.tta_type == "median":
prediction = torch.stack(predictions).median(dim=0).values
elif self.tta_type == "product":
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
a31eaa4 to
d065b77
Compare
VSUNet.perform_test_time_augmentations had its own rotation implementation (_rotate_volume: square-pad + monai Rotate90 + _crop_to_original), separate from the AugmentedPredictionVSUNet transform-list path. Unify both on rotation_tta_transforms() + _pad_forward_crop, which crops to the augmented shape before the inverse rotation -- so non-square FOVs work without square padding (single source of truth for rotation TTA). - Drop _rotate_volume, _crop_to_original, the _original_shape_yx attribute, and the now-unused Rotate90 import. - Behavior change: for non-square FOVs the viscy predict TTA output now uses bare rot90 (no zero-padded border regions); square FOVs are unchanged. - product/mean/median reductions preserved. - Add non-square regression test for perform_test_time_augmentations. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d065b77 to
7385739
Compare
Stacked on #450.
Summary
VSUNet.perform_test_time_augmentations(theviscy predictTTA path) had its own rotation implementation —_rotate_volume(square-pad + monaiRotate90) +_crop_to_original— separate fromAugmentedPredictionVSUNet's transform-list path. This unifies both on therotation_tta_transforms()helper added in #450, so rotation TTA has a single source of truth.perform_test_time_augmentationsnow builds its rotations fromrotation_tta_transforms()and reuses_pad_forward_crop, which crops to the augmented shape before the inverse rotation — so non-square FOVs work with baretorch.rot90, no square padding._rotate_volume,_crop_to_original, the_original_shape_yxattribute, and the now-unusedRotate90import.mean/median/productreductions preserved.Behavior change (intended)
For non-square FOVs,
viscy predictTTA output changes: the old path zero-padded to a square before rotating (introducing border regions that were cropped back out); the new path rotates without padding. Square FOVs are unchanged. This is a correctness improvement for non-square inputs.Test plan
test_vsunet_perform_test_time_augmentations_nonsquare(64×64, 64×48, 48×64 × mean/median).pytest test_engine.py -k "tta or rotation or augment or sliding_windows"→ 15 passed.🤖 Generated with Claude Code