ClinicalDataScience / datacentric-challenge

Apache License 2.0
7 stars 3 forks source link

mt.ResampleToMatch in prediction #5

Open maxshatskiy opened 2 months ago

maxshatskiy commented 2 months ago

https://github.com/ClinicalDataScience/datacentric-challenge/blob/main/predict.py There is a output = mt.ResampleToMatch()(prediction[0], reference[None, ...], mode="nearest") line. The shapes of the prediction and reference image: shape of prediction.shape torch.Size([1, 1, 400, 400, 588]) shape of reference[None, ...] torch.Size([1, 400, 400, 588]) shape of output (prediction[0]) torch.Size([1, 400, 400, 588]) shape of gt torch.Size([400, 400, 588]) reference.meta['pixdim'][1:4] [2.03642 2.03642 3. ]

If I do not use this resampling, since I think there is nothing to resample, : output = prediction[0] then I get the following results: {'dice_score': 0.614188644477715, 'fp_volume': 9.318324703216552, 'fn_volume': 0.6469330902099609} without_resample

If I use resampling as specified: output = mt.ResampleToMatch()(prediction[0], reference[None, ...], mode="nearest") results is the following: {'dice_score': 0.0, 'fp_volume': 7.37752543258667, 'fn_volume': 125.01981968307494} with_resample

Is this something that expected/normal?

maxshatskiy commented 2 months ago

Not sure if this is issue with mt.ResampleToMatch or I missed something in the original code, but if instead of:

output = mt.ResampleToMatch()(prediction[0], reference[None, ...], mode="nearest")

to use torch.nn.Upsample:

m=torch.nn.Upsample(size=reference.shape, # XYZ scale_factor=None, mode='nearest', align_corners=None, recompute_scale_factor=None) output = m(prediction) # prediction of shape NCXYZ

then it works.

JakobDexl commented 2 months ago

Hmm that's interesting. I will have a look into that. Thanks for reporting!

JakobDexl commented 2 months ago

@maxshatskiy i was not able to reproduce your error. The MSE between the prediction and the resampled output is zero in my tests (same file). The monai version i used was 1.3.0. Could you provide additional details eg package versions or perhaps an executable file to further investigate this issue. Best Jakob

maxshatskiy commented 1 month ago

@JakobDexl I upgraded monai to the latest version. Probably I do something wrong with dimensions, but not able to track the error. The solution with torch.nn.Upsample works fine. I just want to make sure that this is not some general bug and if it works fine for you, then it should be just bug in my code.