KidsWithTokens / MedSegDiff

Medical Image Segmentation with Diffusion Model
MIT License
979 stars 147 forks source link

Debug Output Images #106

Open ToruHironaka opened 1 year ago

ToruHironaka commented 1 year ago

I generated a debug output image like below while I was testing. I defined each image of the debug output images listed below. Is my definition of the output images correct? Please correct me if my definition is incorrect.

Output Image: Images between 1 through 4 are normalized.

1: Original image t1 (o1)

  1. Original Image t1ce (o2)

  2. Original image t2 (o3)

  3. Original Image flair (o4)

  4. Original Image t1 without normalization (m)

  5. The sample image from the model (each time step of diffusion from 0 through 999) (s)

  6. The segmentation Image from the trained model output (c)

  7. An overlapping images of the final image of random samples and the final prediction image.

image

saisusmitha commented 1 year ago

@ToruHironaka Can you tell me how many steps you trained it? Also is the last but one Ground truth or the sample segmentation from the model?

ToruHironaka commented 1 year ago

Your question: Can you tell me how many steps you trained it?

My Answer:

The training diffusion step was 1000. I follow the below script with the arguments posted on the README page.

  1. For training, run: python scripts/segmentation_train.py --data_name ISIC --data_dir input data direction --out_dir output data direction --image_size 256 --num_channels 128 --class_cond False --num_res_blocks 2 --num_heads 1 --learn_sigma True --use_scale_shift_norm False --attention_resolutions 16 --diffusion_steps 1000 --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False --lr 1e-4 --batch_size

The training session generated the last model called "emasavedmodel_0.9999_135000.pt."

Here are the training logs.

log.txt

progress.csv

I ran the below script with the training model and the arguments to generate the above image. I used Brast2020 data.

python scripts/segmentation_sample.py --data_dir /data/BraTS2020/Data/MICCAI_BraTS2020_ValidationData/ \ --out_dir ./results_BraTS2020_sample_dpm_solver_0.9999_135000 --model_path ./results_BraTS2020/emasavedmodel_0.9999_135000.pt \ --data_name BRATS --image_size 256 --num_channels 128 --class_cond False --num_res_blocks 2 --num_heads 1 \ --learn_sigma True --use_scale_shift_norm False --attention_resolutions 16 --diffusion_steps 50 --dpm_solver True \ --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False --num_ensemble 5 --multi_gpu 0,1 --debug True

Your Quesiton: Also, is the last but one Ground truth or the sample segmentation from the model? <-- This is my question too.

My answer:

I think your script "segmentation_sample.py" line 126 and lines between 153 and 159 assign the output images.

Here is the image of the code: output_images

Code:

Line: 126 co = th.tensor(cal_out)

Line: 153-159 s = th.tensor(sample)[:,-1,:,:].unsqueeze(1) m = th.tensor(m.to(device = 'cuda:0'))[:,0,:,:].unsqueeze(1) o1 = th.tensor(org)[:,0,:,:].unsqueeze(1) o2 = th.tensor(org)[:,1,:,:].unsqueeze(1) o3 = th.tensor(org)[:,2,:,:].unsqueeze(1) o4 = th.tensor(org)[:,3,:,:].unsqueeze(1) c = th.tensor(cal)

I checked each output image s, m, o1, o2, o3, o4, c. I think these output images were defined below. I am pretty sure that my definitions of the output images between 1 through 5 below is correct, but I am not sure about the rest of the output images. I might be totally wrong though. I would like to confirm with you that all my definitions of the output images are correct.

1: BraTS20_Validation_001_t1.nii.gz (o1) [normalized]

  1. BraTS20_Validation_001_t1ce.nii.gz (o2) [normalized]
  2. BraTS20_Validation_001_t2.nii.gz (o3) [normalized]
  3. BraTS20_Validation_001_flair.nii.gz (o4) [normalized]
  4. BraTS20_Validation_001_t1.nii.gz (m) [not normalized]
  5. The final image of random samples from the model (p_sample_loop_progressive
    from 0 through 999) (s)
  6. The segmentation Image from the trained model output (c)
  7. The overlapping images of the final image of random samples and the final prediction image.

Here is my input data looks like. brast2020_input_data

chenyu1330 commented 3 months ago

I have some questions for you to add a Wechat 18707020678

Your question: Can you tell me how many steps you trained it?

My Answer:

The training diffusion step was 1000. I follow the below script with the arguments posted on the README page.

  1. For training, run: python scripts/segmentation_train.py --data_name ISIC --data_dir input data direction --out_dir output data direction --image_size 256 --num_channels 128 --class_cond False --num_res_blocks 2 --num_heads 1 --learn_sigma True --use_scale_shift_norm False --attention_resolutions 16 --diffusion_steps 1000 --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False --lr 1e-4 --batch_size

The training session generated the last model called "emasavedmodel_0.9999_135000.pt."

Here are the training logs.

log.txt

progress.csv

I ran the below script with the training model and the arguments to generate the above image. I used Brast2020 data.

python scripts/segmentation_sample.py --data_dir /data/BraTS2020/Data/MICCAI_BraTS2020_ValidationData/ --out_dir ./results_BraTS2020_sample_dpm_solver_0.9999_135000 --model_path ./results_BraTS2020/emasavedmodel_0.9999_135000.pt --data_name BRATS --image_size 256 --num_channels 128 --class_cond False --num_res_blocks 2 --num_heads 1 --learn_sigma True --use_scale_shift_norm False --attention_resolutions 16 --diffusion_steps 50 --dpm_solver True --noise_schedule linear --rescale_learned_sigmas False --rescale_timesteps False --num_ensemble 5 --multi_gpu 0,1 --debug True

Your Quesiton: Also, is the last but one Ground truth or the sample segmentation from the model? <-- This is my question too.

My answer:

I think your script "segmentation_sample.py" line 126 and lines between 153 and 159 assign the output images.

Here is the image of the code: output_images

Code:

Line: 126 co = th.tensor(cal_out)

Line: 153-159 s = th.tensor(sample)[:,-1,:,:].unsqueeze(1) m = th.tensor(m.to(device = 'cuda:0'))[:,0,:,:].unsqueeze(1) o1 = th.tensor(org)[:,0,:,:].unsqueeze(1) o2 = th.tensor(org)[:,1,:,:].unsqueeze(1) o3 = th.tensor(org)[:,2,:,:].unsqueeze(1) o4 = th.tensor(org)[:,3,:,:].unsqueeze(1) c = th.tensor(cal)

I checked each output image s, m, o1, o2, o3, o4, c. I think these output images were defined below. I am pretty sure that my definitions of the output images between 1 through 5 below is correct, but I am not sure about the rest of the output images. I might be totally wrong though. I would like to confirm with you that all my definitions of the output images are correct.

1: BraTS20_Validation_001_t1.nii.gz (o1) [normalized] 2. BraTS20_Validation_001_t1ce.nii.gz (o2) [normalized] 3. BraTS20_Validation_001_t2.nii.gz (o3) [normalized] 4. BraTS20_Validation_001_flair.nii.gz (o4) [normalized] 5. BraTS20_Validation_001_t1.nii.gz (m) [not normalized] 6. The final image of random samples from the model (p_sample_loop_progressive from 0 through 999) (s) 7. The segmentation Image from the trained model output (c) 8. The overlapping images of the final image of random samples and the final prediction image.

Here is my input data looks like. brast2020_input_data

chenyu1330 commented 3 months ago

Doesn't this m represent a real mask diagram?

I generated a debug output image like below while I was testing. I defined each image of the debug output images listed below. Is my definition of the output images correct? Please correct me if my definition is incorrect.

Output Image: Images between 1 through 4 are normalized.

1: Original image t1 (o1)

  1. Original Image t1ce (o2)
  2. Original image t2 (o3)
  3. Original Image flair (o4)
  4. Original Image t1 without normalization (m)
  5. The sample image from the model (each time step of diffusion from 0 through 999) (s)
  6. The segmentation Image from the trained model output (c)
  7. An overlapping images of the final image of random samples and the final prediction image.

image