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

Inference script that inputs mha slices #35

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

fennievdg
Copy link

Hi Reginabarzilay group,

Firstly, thank you for making your code publically available! I would find it very useful to have an implementation of your Sybil code that inputs .mha slices (as well as .dcm slices). I have an inference script that inputs mha slices and I also made a few updates in serie.py to load them with SimpleITK. However when I compared the risk scores that I obtained with loading the .dcm slices with the risk scores from loading the .mha slices for the same case, I did not get the same risk scores. Perhaps you can suggest how to fix my implementation to load the mha slices?

Thank you!
Fennie van der Graaf

@pgmikhael
Copy link
Collaborator

pgmikhael commented Mar 18, 2024

Hi Fennie,

Thanks for following up and making the PR! We had some recent updates to the repo, so many of the "changed" files in your commit are probably from an older version. It looks like the main changes are in:

  • inference_fennie.py
  • sybil/loaders/image_loaders.py

Am I missing something else that's important?

In terms of figuring out the discrepancy in risk scores, do you have the same CT in both formats (DICOM/MHA or PNG/MHA)? Also, do you have a test sample that you can share so that we might take a closer look?

@pgmikhael pgmikhael self-assigned this Mar 18, 2024
…ybil

I have been converting a stacked 3D mha into 2D .dcm slices to input into Sybil using this script.
@fennievdg
Copy link
Author

Hi,

Thanks for your quick reaction. Yes, The main changes were performed in inference_fennie.py, image_loaders.py, and in serie.py.

I am not sure yet if I can share a test case, I am waiting on my supervisor to suggest how to go about that, but for now you can replicate my inputs using a NLST mha file and the following 2 scripts:

  • In general, to run Sybil, I first convert a 3D mha into dcm slices, to do so I use the mha2dicom.py script I commited.
  • To try the mha implementation, I convert a 3D mha into mha slices using the unstackandordermha.py script I commited.
  • Where I think the issue is; in order to avoid the below error, I needed to make the pixel spacing 3D: so it includes [pixel spacing x, pixel spacing y, slice thickness] and then gets added to the slice thickness to get the voxel spacing, which resulted in [pixel spacing x, pixel spacing y, slice thickness, slice thickness], otherwise it considered voxel spacing to be the wrong shape and so None.
  • So basically I did not understand what needed to be in the third dimension of the voxel spacing to get the (4,4) shape.

Traceback (most recent call last):
File "/data/bodyct/experiments/Sybil_Fennie/bodyct-sybil-lung-cancer-risk/inference_fennie.py", line 127, in
scores = model.predict([serie])
File "/data/bodyct/experiments/Sybil_Fennie/bodyct-sybil-lung-cancer-risk/sybil/model.py", line 286, in predict
pred = self._predict(sybil, series)
File "/data/bodyct/experiments/Sybil_Fennie/bodyct-sybil-lung-cancer-risk/sybil/model.py", line 259, in _predict
volume = serie.get_volume()
File "/data/bodyct/experiments/Sybil_Fennie/bodyct-sybil-lung-cancer-risk/sybil/serie.py", line 163, in get_volume
x = tio.ScalarImage(
File "/usr/local/lib/python3.9/site-packages/torchio/data/image.py", line 815, in init
super().init(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/torchio/data/image.py", line 158, in init
affine = self._parse_affine(affine)
File "/usr/local/lib/python3.9/site-packages/torchio/data/image.py", line 514, in _parse_affine
raise ValueError(f'Affine shape must be (4, 4), not {bad_shape}')
ValueError: Affine shape must be (4, 4), not (3, 3)

Let me know if you need further clarification! Thanks!
Fennie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants