How is upsampling perform (at inference) ? #2531
Replies: 2 comments 1 reply
-
Hello Romain, The scripts you are seeking fore are in nnunetv2->inference->predict_from_raw_data.py. Main script called from them is in nnunetv2->inference->export_prediction.py (convert_predicted_logits_to_segmentation_with_correct_shape). That script is calling predicted_logits = configuration_manager.resampling_fn_probabilities() where it uses resampling_fn_probabilities which is partial function of proper resample method. How is inference done? Essentially it is overlapping windows (script predict_sliding_window_return_logits ) which also implement gaussian weighting. It creates volume logits predictions and then carefully reassemble volume back from the patches. Resample can be found in preprocessing->resampling. Now based on anisotropic and isotropic spacing different resample interpolations are used. Those are described in paper and are buried in code behind plans. Generally: Time is slow, there is no argue about it because it heavily depends on input CT shape - the bigger the CT the more time and memory it consumes. In my opinion, if you want to do workaround and can sacrifice some precision - reshape the nifti file prior giving it to the nnUnet or break it down into several smaller ones. It is bad workaround but at least you should avoid memory problems. Without heavy alterations to the code, I am not seeing how you can easily adjust nnUnet code to your problem. Best, P.S. I am also reading nnUnet code and try to understand everything, there may be that I have not understand something properly, but this is all I know and understand for now. Code is hard, it is a lot of everything everywhere and you need to dwell really deep into it to understand how everything works. For 100% correct answer, Fabian is the boss. |
Beta Was this translation helpful? Give feedback.
-
Hi Franko I quote the resize_segmentation comment: The small difference I do still see is that argmax is not use at the end to revert back to a 3D label map In case of voxel with more than 2 label in partial volume this could make a difference, (not sure if it is a big deal or not) . Anyway avoiding the argmax also allow to no have to store the full 4D onhot image and thus it spares a lot of memory ! ... The last point which is not fully clear to me, is wether the resampling is done on the full volume (ie after resambling the sliding widows inference patches) or directly at the patch level before merging the patches ? I forgot about possible anisotropy, but in case of isotropic voxel size for training I guess every thing is done isotropic |
Beta Was this translation helpful? Give feedback.
-
Hello
I trained for (MRI) brain segmentation a nnUNet model with a dataset at 0.75 mm iso.
At inference , I tested a very hig resolution input volume (0.25 mm)
If I understand correctly the way nnunet process, is to first resample the input volume to the training set resolution (0.75) and then upsample back the result.
Can you describe (or point me the corresponding code) how this is perform ?
I try to reproduce :
If I perform this two step myself, the easiest (usual) way to perform it is to use nearest interpolation to upsample the (binary) label. The result is an effective resolution much bigger compare to result of nn-unet -> nnunet gives me very smooth boundary whereas the nearest interpolation does not improve the resolution (ie I do see pixelesize boudary (~0.75mm) )
Actually I found a way to improve the upsampling of a label map, (not sure if this is well know ?) :
The idea is to first transform the 3D label volume to a 4D onehot version and then to upsample each channel (with any interpolation scheme, spline, or cubic) and finally perform the argmax to end up with a binary 3D upsapled volume.
The biggest issue with this method, is time and memory: if there are too much label and too high resolution, the onehot is just too big ... is there a way to do it patch wise ?
I would be very interested to understand how you handle this in nnUNet.
Many thanks
Romain
Beta Was this translation helpful? Give feedback.
All reactions