MIC-DKFZ / nnUNet

Apache License 2.0
5.85k stars 1.75k forks source link

Would like to save each label as a separate .nii.gz file during the inference phase? #2491

Open Hollycooool opened 1 month ago

Hollycooool commented 1 month ago

Hi, there are four categories of labels in my dataset.json, and now the prediction is 4 labels per patient in one nii.gz file, if I want to output a specific nii.gz file for each patient's label in the inference phase, i.e. 4 different nii.gz files for each patient, which part of the nnunet should I modify? If I want to output a specific nii.gz file for each patient label in the reasoning phase, i.e. 4 different nii.gz files for each patient, which part of nnunet should I modify?

Hollycooool commented 1 month ago

I want to remove the softmax layer from the end of the network during the inference phase and output the probabilities of a voxel belonging to different labels.Thanks!

sten2lu commented 1 month ago

Hi @Hollycooool,

to write out the softmax probabilities the network returns alongside the segmentations during the prediction use the --save_probabilties flag.

This will save .npz files in the ouptut folder in which the probabilities for each class are saved.

Best regards, Carsten

Hollycooool commented 1 month ago

What I'm wondering is whether the .npz file saved by --save_probabilties contains the un-normalized predicted values of the image before it goes through the softmax layer?

I'd like to get the model's un-normalized predicted values when the prediction is complete, which means saving the logits image (without going through Softmax), saving the logits tensor directly as .npz, and also making sure that the output is a separate channel for each label's score.

Is this achievable? Thanks!

sten2lu commented 1 month ago

Hi @Hollycooool To get the logits of nnU-Net you will have to change the inference code of nnU-Net. As of yet we do not support this.

--save_probabilities saves the probabilities per class inside the.npz file.

To get a better understanding of the inference code, I refer you to the documentation.

Best regards Carsten

Hollycooool commented 1 month ago

As a noob, do I need to modify the network framework at train, and which class under the py file in the reasoning folder should I modify? Thanks!

sten2lu commented 18 hours ago

Hi @Hollycooool, The necessary steps are detailed in the README.md in the folder nnunetv2/inference.

Best regards, Carsten