nnUNet icon indicating copy to clipboard operation
nnUNet copied to clipboard

Confusion about loss calculation of region-based tasks

Open Chenyang-1024 opened this issue 1 year ago • 2 comments

For region-based segmentation tasks, such as BraTS 2021, whose labels contain four values: 0, 1, 2 and 3, I found that trainer will set num_classes to 3, ignoring the background class, but strangely, when instantiating the loss function DC_and_BCE_loss, it will set the do_bg to True? Moreover, in the calculation of dice loss, firstly, an all-zero tensor y_onehot with the same dimension as the network output is created, that is, (B, num_classes, D, H, W), and then gt is scattered into y_onehot by y_onehot.scatter_ (1, gt, 1) operation to obtain the one-hot coding of gt. However, the label values in gt contain four values: 0, 1, 2, 3, while the number of channels of y_onehot is only 3!!! Doesn't this mean that labels with a value of 3 will be discarded? Won't this cause problems?

Chenyang-1024 avatar Dec 06 '23 04:12 Chenyang-1024

Maybe my question is solved:) The region-based gt is transformed in Data Augmentation, the class ConvertSegmentationToRegionsTransform will be called.

Chenyang-1024 avatar Dec 06 '23 12:12 Chenyang-1024

Hi! I had a new question, in the region-based task, is there any place where training, validation or inference need to convert the regions back to segmentation map? Because I didn't seem to find the relevant code implementation to convert the regions back to segmentation map.

Chenyang-1024 avatar Dec 06 '23 13:12 Chenyang-1024

Hi @Chenyang-1024 , sorry for leaving this new question unanswered for so long! However, I'm not entirely sure I understand your last question. Does the documentation on region based training (https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/region_based_training.md) cover your question?

GregorKoehler avatar Apr 22 '24 12:04 GregorKoehler

Closing this issue as it's stale for a week now. Please feel free to re-open if you're still facing issues!

GregorKoehler avatar Apr 27 '24 08:04 GregorKoehler