Giter VIP home page Giter VIP logo

Comments (8)

rohanbanerjee avatar rohanbanerjee commented on September 7, 2024 1

Sharing the image and it's corresponding prediction by the nnUNet model below:

Image: sub-genevaR303_task-rest_rec-MoCoMean_bold.nii.gz
Prediction: sub-genevaR303_task-rest_rec-MoCoMean_bold.nii.gz

When I use the above to generate the QC, it throws the below error:

File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/nibabel/processing.py", line 177, in resample_from_to
    to_vox2from_vox = npl.inv(a_from_affine).dot(a_to_affine)
ValueError: shapes (4,4) and (5,5) not aligned: 4 (dim 1) != 5 (dim 0)

SCT version SHA: bb7b8d48ab321975a46821b54b7573e8e7863fe5

from spinalcordtoolbox.

joshuacwnewton avatar joshuacwnewton commented on September 7, 2024

When I call sct_image -header -i sub-genevaR303_task-rest_rec-MoCoMean_bold.nii.gz, it looks like the sform/qform are already the same, meaning that -set-qform-to-sform will have no effect.

qform_name	Scanner Anat
qform_code	1
qto_xyz:1	-1.000000 0.000000 0.000000 70.000000 
qto_xyz:2	0.000000 0.968657 0.745207 -51.336601 
qto_xyz:3	0.000000 -0.248402 2.905971 -47.205898 
qto_xyz:4	0.000000 0.000000 0.000000 1.000000 
qform_xorient	Right-to-Left
qform_yorient	Posterior-to-Anterior
qform_zorient	Inferior-to-Superior
sform_name	Scanner Anat
sform_code	1
sto_xyz:1	-1.000000 0.000000 0.000000 70.000000 
sto_xyz:2	0.000000 0.968657 0.745207 -51.336601 
sto_xyz:3	0.000000 -0.248402 2.905971 -47.205898 
sto_xyz:4	0.000000 0.000000 0.000000 1.000000 
sform_xorient	Right-to-Left
sform_yorient	Posterior-to-Anterior
sform_zorient	Inferior-to-Superior

Could you describe the larger context of the issue? (What problem are you trying to fix by running this command?)

from spinalcordtoolbox.

rohanbanerjee avatar rohanbanerjee commented on September 7, 2024

So I am running inference on my data using my latest segmentation model. In my same script, I am also generating the qc in the same script. Details below

Link to the script used: https://github.com/sct-pipeline/fmri-segmentation/blob/main/inference/run_inference.py

A sample datatset:
test.zip

Link to the model weights:
https://drive.google.com/file/d/1yQeBb7gF-4L-0fE4nvms-gu7JzOXkgiK/view?usp=sharing

Command used:
python run_inference.py --path-dataset <PATH_TO_SAMPLE_DATASET> --path-out <PATH_TO_OUTPUT_FOLDER> --path-model <PATH_TO_WEIGHTS/nnUNetTrainer__nnUNetResEncUNetPlans__3d_fullres> --use-best-checkpoint --path-qc <PATH_TO_OUTPUT_FOLDER> --use-gpu

The inference ran successfully on all the images but when the QC started running, the script ran into the following error:

Traceback (most recent call last):
  File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_qc.py", line 121, in <module>
    main(sys.argv[1:])
  File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_qc.py", line 104, in main
    generate_qc(fname_in1=arguments.i,
  File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/spinalcordtoolbox/reports/qc.py", line 768, in generate_qc
    qcslice = SliceSubtype(im_list, p_resample=p_resample)
  File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/spinalcordtoolbox/reports/slice.py", line 61, in __init__
    img_r = self._resample_slicewise(img, p_resample, type_img=type_img, image_ref=image_ref)
  File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/spinalcordtoolbox/reports/slice.py", line 288, in _resample_slicewise
    nii_r = resample_nib(nii, image_dest=nii_ref, interpolation=dict_interp[type_img])
  File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/spinalcordtoolbox/resampling.py", line 127, in resample_nib
    img_r = resample_from_to(
  File "/home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/nibabel/processing.py", line 177, in resample_from_to
    to_vox2from_vox = npl.inv(a_from_affine).dot(a_to_affine)
ValueError: shapes (4,4) and (5,5) not aligned: 4 (dim 1) != 5 (dim 0)

Which I understand is a size mismatch in between the created segmentation mask and the subject image but when I check the info on FSLeyes, I observe the following:

Info of the segmentation mask:
Screenshot 2024-06-13 at 2 33 45 PM

Info of the subject image
Screenshot 2024-06-13 at 2 34 03 PM

I've previously observed this issue did not come up in running the QC (observed that the Sform and Qform matrices have been the same)

from spinalcordtoolbox.

joshuacwnewton avatar joshuacwnewton commented on September 7, 2024

Hmm. The link to the model weights isn't working for me. I'm getting the exact same error as:

dot|joshua@monarch:~/data$ $SCT_DIR/python/envs/venv_sct/bin/python ./4530-shapes/run_inference.py --path-dataset 4530-shapes/ --path-out 4530-shapes/output/ --path-model nnUNetTrainer__nnUNetResEncUNetPlans__3d_fullres/ --use-best-checkpoint --path-qc 4530-shapes/output/qc --use-gpu
Found a dataset folder. Running inference on the whole dataset...
Creating temporary folder with proper filenames...
Starting inference...
Running inference on device: cuda
Traceback (most recent call last):
  File "/home/joshua/data/./4530-shapes/run_inference.py", line 248, in <module>
    main()
  File "/home/joshua/data/./4530-shapes/run_inference.py", line 206, in main
    predictor.initialize_from_trained_model_folder(
  File "/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/nnunetv2/inference/predict_from_raw_data.py", line 84, in initialize_from_trained_model_folder
    checkpoint = torch.load(join(model_training_output_dir, f'fold_{f}', checkpoint_name),
  File "/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/torch/serialization.py", line 1005, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/home/joshua/repos/spinalcordtoolbox/python/envs/venv_sct/lib/python3.9/site-packages/torch/serialization.py", line 457, in __init__
    super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory

The model weights appear to be corrupted?

Anyway, it would be really helpful for me if you could share just the data necessary for the QC report. (This command, I assume? In that case, the input image and the segmentation image.)

That way I don't have to run the full processing pipeline from scratch...

from spinalcordtoolbox.

joshuacwnewton avatar joshuacwnewton commented on September 7, 2024

Hmm. I am seeing no errors with the data you have provided. Here is the log:

(venv_sct) dot|joshua@monarch:~/data/4530-bold-qc$ sct_qc -i sub-genevaR303_task-rest_rec-MoCoMean_bold.nii.gz -s sub-genevaR303_task-rest_rec-MoCoMean_bold_seg.nii.gz -p sct_deepseg_sc

--
Spinal Cord Toolbox (git-HEAD-bb7b8d48ab321975a46821b54b7573e8e7863fe5)

sct_qc -i sub-genevaR303_task-rest_rec-MoCoMean_bold.nii.gz -s sub-genevaR303_task-rest_rec-MoCoMean_bold_seg.nii.gz -p sct_deepseg_sc
--


*** Generate Quality Control (QC) html report ***
Resampling image "sub-genevaR303_task-rest_rec-MoCoMean_bold.nii.gz" to 0.6x0.6 mm
Resampling image "sub-genevaR303_task-rest_rec-MoCoMean_bold_seg.nii.gz" to 0.6x0.6 mm
Converting image from type 'uint8' to type 'float64' for linear interpolation
Image header specifies datatype 'float64', but array is of type 'int64'. Header metadata will be overwritten to use 'int64'.
QcImage: layout with Axial slice
Compute center of mass at each slice
./qc/joshua/data/4530-bold-qc/sct_deepseg_sc/2024_07_04_130107.593541/background_img.png
Successfully generated the QC results in ./qc/_json/qc_2024_07_04_130107.593541.json

To see the results in a browser, type:
xdg-open ./qc/index.html

image

Could you confirm the command you're using for this data matches mine? (Note that the two images you shared have the same name, so I renamed the segmentation to _seg.nii.gz just to avoid conflicts.)

from spinalcordtoolbox.

joshuacwnewton avatar joshuacwnewton commented on September 7, 2024

@rohanbanerjee Would you be able to run sct_check_dependencies as well? (Just to compare the versions of packages with my local versions, too.)

from spinalcordtoolbox.

rohanbanerjee avatar rohanbanerjee commented on September 7, 2024

Apologies for the delay in response.

This is what sct_check_dependencies gives me:

SYSTEM INFORMATION
------------------
SCT info:
- version: git-rb/4558-add-dog-template-b61e237ba38f48d71aab7f6bf3fb006df09962f9
- path: /home/GRAMES.POLYMTL.CA/robana/spinalcordtoolbox
OS: linux (Linux-6.8.0-39-generic-x86_64-with-glibc2.39)
CPU cores: Available: 40, Used by ITK functions: 40
RAM: Total: 773908MB, Used: 2375MB, Available: 767374MB

from spinalcordtoolbox.

joshuacwnewton avatar joshuacwnewton commented on September 7, 2024

Sorry to bother, but the reason I ask for sct_check_dependencies is to see the versions of all of the packages (to compare with my local copy). So, could you please share the full output, rather than just the system information part?

(Also, could you check #4530 (comment)? I mostly want to make sure I am using the right command, as it is possible that the command I used was different than the one you used originally.)

from spinalcordtoolbox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.