Fix RandGridDistortiond converting entire dict when transform is skipped#8862
Fix RandGridDistortiond converting entire dict when transform is skipped#8862AlexanderSanin wants to merge 4 commits into
Conversation
) Catching BaseException inadvertently suppresses KeyboardInterrupt, SystemExit, and GeneratorExit, which should nearly always propagate. All 17 occurrences across monai/ and tests/ are replaced with Exception, which is the appropriate base class for catchable errors. Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
…ped (Project-MONAI#8604) When _do_transform is False, RandGridDistortiond called convert_to_tensor on the entire data dictionary, which converted non-image metadata values (integers, strings) into tensors. This caused AttributeError ('int' object has no attribute 'numel') during DataLoader collation. Only convert the transform's target keys instead of the whole dict, consistent with how the transform handles its keys in the normal (do_transform=True) path. Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR narrows many broad exception handlers from catching BaseException to catching Exception across module init, TF32 detection, auto3dseg processing, detection metrics, nnUNet runner, inferer, device config, and tests. It also fixes RandGridDistortiond’s skip-augmentation path to convert only selected keys in-place (resolving a DataLoader collation AttributeError). Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…@gmail.com> I, Oleksandr Yizchak Sanin <alexaaander.sanin@gmail.com>, hereby add my Signed-off-by to this commit: 37db0ad Signed-off-by: Oleksandr Yizchak Sanin <alexaaander.sanin@gmail.com>
Add explicit dict[Hashable, torch.Tensor] type annotation to the convert_to_tensor call in the first_key == () branch to satisfy mypy's no-any-return check. Signed-off-by: Oleksandr Yizchak Sanin <alexaaander.sanin@gmail.com>
Summary
Fixes #8604
When
_do_transformisFalse(transform randomly skipped),RandGridDistortiondcalledconvert_to_tensoron the entire data dictionary. This converted non-image metadata values (integers, strings) into 0-dim tensors, causingAttributeError: 'int' object has no attribute 'numel'during DataLoader collation.The fix only converts the transform's target keys (via
self.key_iterator), consistent with how the transform processes keys in the normal code path.Test plan
RandGridDistortiondwithprob=0no longer crashes in DataLoader withnum_workers > 0test_rand_grid_distortiondtests passSigned-off-by: Oleksandr Sanin alexaaander.sanin@gmail.com