Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to visualise my training dataset to confirm it is being correctly loaded? #167

Open
emmanuel-nwogu opened this issue Apr 16, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@emmanuel-nwogu
Copy link

ct_scans/
   scan_a/
      segmentation.nii.gz
      imaging.nii.gz
   scan_b/
      segmentation.nii.gz
      imaging.nii.gz
   scan_c/
      segmentation.nii.gz
      imaging.nii.gz

Above is the file structure of my dataset where segmentation.nii.gz and imaging.nii.gz are 3D NIFTI files with multiple slices. Also, I'm using code resembling the piece below to load the dataset.

interface = NIFTI_interface(channels=1, classes=2)
data_path = r".\ct_scans"
data_io = Data_IO(interface, data_path)

I'm especially worried about my training data loading because I had to change the slice_axis in the NIFTIslicer_interface init for the sample_data size to be correct while following this tutorial.
When I run sample = data_io.sample_loader("scan_c", load_seg=True), I get a Sample of shape (H, W, N, C). N is my number of slices and my C = 1.

I found visualize_samples but I think it may be bugged. At this line, it tries to convert the sample to grayscale, even though my num of channels is 1, which leads to an IndexError. Here are the code and error respectively.

sample = data_io.sample_loader("scan_c", load_seg=True)
visualize_samples([sample], mask_seg=True, mask_pred=False)

Error:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/nwogu/OneDrive/Documents/4mLab/MIScnn-UNet/data_io.py", line 39, in <module>
    visualize_samples([sample], mask_seg=True, mask_pred=False)
  File "C:\Users\nwogu\AppData\Local\Programs\Python\Python39\lib\site-packages\miscnn\utils\visualizer.py", line 154, in visualize_samples
    sample.img_data = normalize(sample.img_data, to_greyscale=True, normalize=True)
  File "C:\Users\nwogu\AppData\Local\Programs\Python\Python39\lib\site-packages\miscnn\utils\visualizer.py", line 99, in normalize
    return normalize_volume(sample, to_greyscale, normalize)
  File "C:\Users\nwogu\AppData\Local\Programs\Python\Python39\lib\site-packages\miscnn\utils\visualizer.py", line 48, in normalize_volume
    img[:, :, :] = vec_luminosity(img[:, :, :, 0], img[:, :, :, 1], img[:, :, :, 2])
IndexError: index 1 is out of bounds for axis 3 with size 1

I may be misusing it though, I am not sure. Please, let me know. :)

As an aside but kinda related, I tried writing my own visualize_samples but I could not find the definition of overlay_segmentation as used here.

@emmanuel-nwogu
Copy link
Author

visualize_samples() is bugged as I came to find out from #155. It does seem you are fixing it (#156). Thanks :)

I believe there's another bug that may be missed though. I found this because my data is grayscaled so only one channel. This line in visualize_samples() has the to_greyscale parameter hardcoded as True. Unfortunately, this causes an IndexError here when the img_data is grayscale. Here's an example error dump where my img_data has the shape (370, 512, 256, 1) following the (N, H, W, C) format:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/nwogu/OneDrive/Documents/4mLab/MIScnn-UNet/visualize_results.py", line 109, in <module>
    visualize_samples([sample], out_dir=evaluation_path, mask_seg=True, mask_pred=True,
  File "C:\Users\nwogu\AppData\Local\Programs\Python\Python39\lib\site-packages\miscnn\utils\visualizer.py", line 154, in visualize_samples
    sample.img_data = normalize(sample.img_data, to_greyscale=True, normalize=True)
  File "C:\Users\nwogu\AppData\Local\Programs\Python\Python39\lib\site-packages\miscnn\utils\visualizer.py", line 99, in normalize
    return normalize_volume(sample, to_greyscale, normalize)
  File "C:\Users\nwogu\AppData\Local\Programs\Python\Python39\lib\site-packages\miscnn\utils\visualizer.py", line 48, in normalize_volume
    img[:, :, :] = vec_luminosity(img[:, :, :, 0], img[:, :, :, 1], img[:, :, :, 2])
IndexError: index 1 is out of bounds for axis 3 with size 1
python-BaseException

cc @muellerdo

@muellerdo muellerdo added the bug Something isn't working label May 10, 2023
@muellerdo
Copy link
Member

Hey @emmanuel-nwogu,

good spot! Thanks!!

Philip (@Deathlymad) implemented the visualization and will have a look on it :)

Best Regards,
Dominik

@Deathlymad
Copy link
Collaborator

afaik this should be fixed on the dev branch @muellerdo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants