JuliaWolleb / Diffusion-based-Segmentation

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

The training is not coming out well, so I hope you can see it and respond! #45

Closed Worker-Hou closed 9 months ago

Worker-Hou commented 1 year ago

Hello! You are great at this job! But when I reproduce this code of yours, the segmentation result I get is very bad. Below is the segmented image I used and the resulting image I got. The training set I used was the BraTS2020 training set using the 80th to 129th axial slices from 332 patients, and the test set was a selected set of images from 37 patients. The steps of the training are 80,000 steps.The final threshold was set to 0.5 as per your paper. not sure if it is because of the dataset. Can you provide me with the number of the patients in the training set you used so that I can train with good results, thanks again!

1 2 3 4 5 6

Worker-Hou commented 1 year ago

Hopefully someone who knows how to fix this can help me. Thanks!

Worker-Hou commented 1 year ago

When I increase the training steps to 100000 steps, and test the 5 segmented images thus generated, there is always one or two images that work very poorly, approximating pure white noise or unable to find the place to be segmented, but the other three or four images are able to get better segmentation results instead. Does anyone have any idea why this is? Thank you very much!

JuliaWolleb commented 1 year ago

Good morning

I think he example images you sent look very weird. Only the last one looks as expected. I don't really onderstand why you have 5 segmented images. Out of the 4 MR input channels, you should only get one output image. Did you implement this accordingly?

Worker-Hou commented 1 year ago

Good morning

I think he example images you sent look very weird. Only the last one looks as expected. I don't really onderstand why you have 5 segmented images. Out of the 4 MR input channels, you should only get one output image. Did you implement this accordingly?

I am basing this on one of your papers: "For every image of the test set, we sample 5 different segmentation masks. This implicitly defines an ensemble by averaging over the 5 masks and thresholding it at 0.5." Then in the test phase we have it generate 5 different images. However, based on my current code reproduction, the segmentation results and the corresponding metrics are significantly improved when taking the number of training sessions up to 300,000, with the exception of some images that get poor results. This makes me wonder, in your paper you got good segmentation results after training only up to 60,000 steps, whereas I need quite long steps. Thanks for your reply! Thanks again for your work and looking forward to what you do next!

1362303119 commented 1 year ago

@Worker-Hou Hello, I am new to diffusion modeling and have tried to reproduce the code, but I am having problems processing the BRATS2020 dataset. Can you share the code you used to process the dataset? My email is mailto:zhanglili_955@163.com,If you can help me to solve this problem, I would be very grateful!

Worker-Hou commented 1 year ago

@Worker-Hou Hello, I am new to diffusion modeling and have tried to reproduce the code, but I am having problems processing the BRATS2020 dataset. Can you share the code you used to process the dataset? My email is mailto:zhanglili_955@163.com,If you can help me to solve this problem, I would be very grateful!

Hi, Ask ChatGpt this question it will give you the complete code!

Worker-Hou commented 1 year ago

@Worker-Hou Hello, I am new to diffusion modeling and have tried to reproduce the code, but I am having problems processing the BRATS2020 dataset. Can you share the code you used to process the dataset? My email is mailto:zhanglili_955@163.com,If you can help me to solve this problem, I would be very grateful!

Hi, Ask ChatGpt this question it will give you the complete code!

Have emailed you the code I used, FYI.

648lsf commented 11 months ago

Hello! You are great at this job! But when I reproduce this code of yours, the segmentation result I get is very bad. Below is the segmented image I used and the resulting image I got. The training set I used was the BraTS2020 training set using the 80th to 129th axial slices from 332 patients, and the test set was a selected set of images from 37 patients. The steps of the training are 80,000 steps.The final threshold was set to 0.5 as per your paper. not sure if it is because of the dataset. Can you provide me with the number of the patients in the training set you used so that I can train with good results, thanks again!

1 2 3 4 5 6

Hello! Can the results of your final experiment achieve the results in the paper? Why is it so difficult for me to achieve it?

JuliaWolleb commented 11 months ago

Did you double-check the input to your model? the first 4 channels should show the clean (i.e., non-noisy MR images). The 5th channel should show the noisy segmentation mask x_t. The loss is only computed on the noise of the 5th channel. The output should be a 1-channel (if you setlearn_sigma=False) image.

Worker-Hou commented 11 months ago

Did you double-check the input to your model? the first 4 channels should show the clean (i.e., non-noisy MR images). The 5th channel should show the noisy segmentation mask x_t. The loss is only computed on the noise of the 5th channel. The output should be a 1-channel (if you set) image.learn_sigma=False

Yes, my input image looks like the one below: image But your last hyperparameter setting: learn_sigma=False, makes me wonder, isn't your hyperparameter setting set to True?

Worker-Hou commented 11 months ago

你好!你很擅长这份工作!但是当我重现你的这段代码时,我得到的分割结果非常糟糕。下面是我使用的分割图像和我得到的结果图像。我使用的训练集是 BraTS2020 训练集,使用来自 80 名患者的第 129 至 332 个轴向切片,测试集是来自 37 名患者的一组精选图像。培训的步骤是80,000步。根据您的论文,最终阈值设置为 0.5。不确定是否是因为数据集。你能不能给我提供你使用的训练集中的病人数量,这样我就可以训练出好的结果,再次感谢! 1 2 3 4 5 6

你好!你最终的实验结果能达到论文中的结果吗?为什么我很难实现它? Nor could I have achieved such good results using only a few steps in the author's paper. Could it be due to differences in the hardware equipment of each experiment? You can extend the training steps for as long as possible (say 200,000 steps or more).

Worker-Hou commented 11 months ago

您是否仔细检查了模型的输入?前 4 个通道应显示干净(即无噪声的 MR 图像)。第 5 个通道应显示嘈杂的分段掩码x_t。损耗仅根据第 5 个通道的噪声计算。输出应为 1 通道(如果设置)图像。learn_sigma=False

是的,我的输入图像如下所示: 但是您的最后一个超参数设置: image learn_sigma=False,让我想知道,您的超参数设置不是设置为 True 吗?

And when I look at the code, either this --learn_sigma=True or False -- doesn't affect the code. image image image

648lsf commented 11 months ago

我在3090上把batch_size设置为4,跑出来的模型到60000step,会有稍微变好,但是很难达到论文中的那样准确,原因可能是集成方式的问题

JuliaWolleb commented 11 months ago

Regarding learn_sigma flag: If you set learn_sigma=True, you need 2 output channels: one for the mean, and one for the variance. If you set learn_sigma=False, you need 1 output for the mean, and the variance is fixed. Both work well, you just need to decide in the beginning, since this affects the architecture of the U-Net model.

@Worker-Hou , could you try to set the noise level to a small number on your img input4, such that we can check whether there is a binary segmentation mask underneath?

Worker-Hou commented 11 months ago

Regarding learn_sigma flag: If you set learn_sigma=True, you need 2 output channels: one for the mean, and one for the variance. If you set learn_sigma=False, you need 1 output for the mean, and the variance is fixed. Both work well, you just need to decide in the beginning, since this affects the architecture of the U-Net model.

@Worker-Hou , could you try to set the noise level to a small number on your img input4, such that we can check whether there is a binary segmentation mask underneath?

Thanks for your reply, now I set learn_sigma=True for training, but no matter how I conduct training, it always fails to get good results if the training steps are less than 100,000 steps, I wonder if it is due to the problems of GPU and data set division. So far I've trained it to 300,000 steps to get relatively good results.

dddb11 commented 10 months ago

@Worker-Hou Hello, I've encountered the same issue. I've noticed that the loss is decreasing quite rapidly in my training, but the performance is poor. So, I'd like to ask, is your loss consistently decreasing over 100,000 iterations, or is it relatively low from the beginning?

JuliaWolleb commented 10 months ago

In my experience, you can't rely on the loss function to monitor the training. The reason for this is that the amount of noise on the input images is random, so the loss starts to jump up and down. However, this does not mean that the model is not learning. If you want to check the segmentation performance, you need to evaluate some images of the validation set after each epoch. The number of iterations needed also depends on your dataset, and how well the thresholding performs.

dddb11 commented 10 months ago

In my experience, you can't rely on the loss function to monitor the training. The reason for this is that the amount of noise on the input images is random, so the loss starts to jump up and down. However, this does not mean that the model is not learning. If you want to check the segmentation performance, you need to evaluate some images of the validation set after each epoch. The number of iterations needed also depends on your dataset, and how well the thresholding performs.

Thanks for your reply.

Worker-Hou commented 10 months ago

In my experience, you can't rely on the loss function to monitor the training. The reason for this is that the amount of noise on the input images is random, so the loss starts to jump up and down. However, this does not mean that the model is not learning. If you want to check the segmentation performance, you need to evaluate some images of the validation set after each epoch. The number of iterations needed also depends on your dataset, and how well the thresholding performs.

Thank you for your reply. I sampled the loss value of training by observing it before. Different Gpus may get different results after the same training steps. I have found a better result. Thanks again for your advice!

Worker-Hou commented 10 months ago

@Worker-Hou 您好,我遇到了同样的问题。我注意到,在我的训练中,损失正在迅速减少,但表现很差。所以,我想问一下,你的损失是持续减少超过 100,000 次迭代,还是从一开始就相对较低?

正如作者说的,并不能完全通过观察损失值来选择所迭代的步骤,据我现在目前的实验来说,所迭代的步骤越大,往往最后的实验结果就越好,并且训练过程的损失值是随机变化的,因为使用的是L2损失函数。你可以适当的延长你的训练步骤来改善你的实验结果。