Repository navigation
fix(losses): bin each sample from its own range in b-spline GlobalMutualInformationLoss - #9186
tritsystem wants to merge 1 commit into
Conversation
…ualInformationLoss parzen_windowing_b_spline took torch.max/torch.min over the whole batch, so a sample's loss depended on the intensity range of the other images in the batch. Use a per-sample amax/amin, as ITK's Mattes MI does for a single image pair. Batch-of-1 results are unchanged. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: tritsystem <gbranaa4@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
File:
monai/losses/image_dissimilarity.py. This loss is used to compare how similar two images are (common in image registration -- lining up a scan with a reference scan). For one kernel option ("b-spline"), it needs to find the min and max brightness value in the image to build a histogram. Instead of looking at each image's own min/max, the code was computing min/max across the whole batch -- so if you feed it 4 images at once, one bright image can shift the histogram for all the others. I tested this directly: the same image scored -1.2792 alone, but -0.1958 when a brighter image shared its batch -- 85% of the signal gone, just from batch composition. That's a real correctness bug, not just a style issue.Fix: per-sample
torch.amax/torch.aminover the non-batch dimensions. A batch of 1 gives the same results as before. The Gaussian kernel is unaffected.Types of changes
Fixes # .