SuperMedIntel / MedSegDiff

Medical Image Segmentation with Diffusion Model
MIT License
1.09k stars 166 forks source link

Errors while sampling with custom dataset #199

Closed pedropesserl closed 1 month ago

pedropesserl commented 1 month ago
Logging to ../sample/sample_corsican_test
[rank0]: Traceback (most recent call last):
[rank0]:   File "/lustre07/scratch/pesserl/medsegdiff/MedSegDiff/scripts/segmentation_sample.py", line 191, in <module>
[rank0]:     main()
[rank0]:   File "/lustre07/scratch/pesserl/medsegdiff/MedSegDiff/scripts/segmentation_sample.py", line 62, in main
[rank0]:     ds,
[rank0]:     ^^
[rank0]: UnboundLocalError: cannot access local variable 'ds' where it is not associated with a value

Reason: in scripts/segmentation_sample.py it is not defined what should happen in case args.data_name is not ISIC or BRATS.

Suggested fix: in scripts/segmentation_sample.py, import CustomDataset from guided_diffusion and assign ds as necessary.

Also:

loading data from the directory : data/CorsicanFire_test
creating model and diffusion...
[rank0]: Traceback (most recent call last):
[rank0]:   File "/lustre07/scratch/pesserl/medsegdiff/MedSegDiff/scripts/segmentation_sample.py", line 199, in <module>
[rank0]:     main()
[rank0]:   File "/lustre07/scratch/pesserl/medsegdiff/MedSegDiff/scripts/segmentation_sample.py", line 101, in main
[rank0]:     b, m, path = next(data)  #should return an image from the dataloader "data"
[rank0]:                  ^^^^^^^^^^
[rank0]:   File "/home/pesserl/.local/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 631, in __next__
[rank0]:     data = self._next_data()
[rank0]:            ^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/pesserl/.local/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 675, in _next_data
[rank0]:     data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/pesserl/.local/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
[rank0]:     data = [self.dataset[idx] for idx in possibly_batched_index]
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/home/pesserl/.local/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 51, in <listcomp>
[rank0]:     data = [self.dataset[idx] for idx in possibly_batched_index]
[rank0]:             ~~~~~~~~~~~~^^^^^
[rank0]:   File "/lustre07/scratch/pesserl/medsegdiff/MedSegDiff/guided_diffusion/custom_dataset_loader.py", line 50, in __getitem__
[rank0]:     label = int(self.label_list[index])
[rank0]:             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: ValueError: invalid literal for int() with base 10: 'data/CorsicanFire_test/masks/007_gt.png'

These happen because of some unnecessary lines in guided_diffusion/custom_dataset_loader.py.

Suggested fix: comment out lines 47-50 and the last comparison in the file since it's not accomplishing anything.