uni-medical / SAM-Med3D

SAM-Med3D: An Efficient General-purpose Promptable Segmentation Model for 3D Volumetric Medical Image
Apache License 2.0
427 stars 56 forks source link

BraTS2021 dataset preprocessing #46

Closed jhbae1184 closed 3 months ago

jhbae1184 commented 3 months ago

First, thank you very much for sharing this amazing project and source code. Really helpful for my study !!

Sorry but i have a question about BraTS2021 dataset preprocessing. Can you share the details about preparing BraTS_Val* ??

When i run prepare_data_from_nnUNet.py for my BraTS2021 dataset, every 'background' class data (whose volume is all 0) is skipped so that doesn`t save in the dataset folder.

So i removed the code here in prepare_data_from_nnUNet.py

[ if(volume<10): print("skip", target_img_path) continue ] and run train.py. However it has some problems (suddenly the loss is nan, but Dice score is not 0.)

(I check the gt3D consisted of all 0 values, and not sure but guess this is cause of 'background' data)

So i want to know how to construct BraTS 21 dataset.

Thank you again and hope to get an answer ! (If it is my personal issue, sorry in advance for asking bad question ;)) )

adrianzzk commented 3 months ago

I tried to use prepare_data_from_nnUNet.py for my own dataset, but I found it didn't work well, so I wrote my own binary code, the principle is to save only the labels you need, and all others change to background. It's very simple, you can try it. I'm also happy to provide you with my code. BTW,there is a bug in train.py,dice cant print in each epoch,there is only print step dice.I'm really curious about why your loss is nan, but Dice score is not 0.and i fix the dice=0,you can try it. hope my exp can help u :)

Alexz-7 commented 3 months ago

In line 95-96 of the prepare_data_from_nnUNet.py, the conversion is done as follows: gt_arr[gt_arr != idx] = 0 gt_arr[gt_arr != 0] = 1 And the label of background is 0, so I think this is the problem. Hope this can help :)

jhbae1184 commented 3 months ago

@adrianzzk @Alexz-7 Thank you for helpful answer :) Got it, i will try and it will be helpful for my problem. Thank you very much !