JuliaWolleb / Diffusion-based-Segmentation

This is the official Pytorch implementation of the paper "Diffusion Models for Implicit Image Segmentation Ensembles".
MIT License
279 stars 36 forks source link

Code for binary masks? #15

Closed Salihslh closed 1 year ago

Salihslh commented 1 year ago

Hi!

I have been looking for days for how the model generates binary masks and can't find it, could you please help?

It does not seem like the last layer is what is pushing the values to be either 0 or 1 in the generated mask, nor does it hard coded somewhere. I have changed the dataloader so that it loads images where the last channel in those images is a non-binary segmentation mask, so it does not happen here either. Could you please point out function/line that forces the generation of masks to be binary?

Kind regards, Salih

JuliaWolleb commented 1 year ago

Hi

There is no line to push the generated segmentation mask to be binary. To get a binary mask to compute the dice score, we chose a thresholding on the generated segmentation mask. During training, the ground truth segmentation mask is forced to be binary in the line 62 of the file _guideddiffusion/bratsloader.py: label=torch.where(label > 0, 1, 0).float() #merge all tumor classes into one