ANTsX / ANTsPyNet

Pre-trained models and utilities for deep learning on medical images in Python
https://antspynet.readthedocs.io
Apache License 2.0
182 stars 28 forks source link

DTK labeling stops in the middle of processing. #107

Closed sj-choi closed 2 months ago

sj-choi commented 2 months ago

I have been testing ANTsPyNet with more RAM. The 'deep' segmentation processes are functioning as expected, except for the DKT labeling. It halts midway and generates certain messages. Due to the extensive length of the screen output, only the final portion is shown below. How much RAM are expected to run DKT labeling?

Input scalar image: 0x9830d550 Could not create ImageIO for the input file, assuming dimension = 3 and scalar pixel type Reference image: 0x22727140

The composite transform comprises the following transforms (in order):

  1. inverse of /tmp/tmpzrfb2a2j0GenericAffine.mat (type = AffineTransform)

    Default pixel value: 0.0000e+00 Interpolation type: LinearInterpolateImageFunction Output warped image: 0x21c9cc70 ['-d', '3', '-i', '0x22722b10', '-o', '0x227adb90', '-r', '0x193e9ee0', '-n', 'linear', '-t', '[/tmp/tmpzrfb2a2j0GenericAffine.mat,1]'] Using double precision for computations. Input scalar image: 0x22722b10 Could not create ImageIO for the input file, assuming dimension = 3 and scalar pixel type Reference image: 0x193e9ee0

    The composite transform comprises the following transforms (in order):

  2. inverse of /tmp/tmpzrfb2a2j0GenericAffine.mat (type = AffineTransform)

    Default pixel value: 0.0000e+00 Interpolation type: LinearInterpolateImageFunction Output warped image: 0x227adb90 Traceback (most recent call last): File "/home/xubuntu/scripts/ANTsPyNet_deep_segmentation_w_BASH_SPRINT_n4_hm_test.py", line 75, in ants.image_write(dkt_results['segmentation_image'], dkt) File "/home/xubuntu/anaconda3/envs/py310/lib/python3.10/site-packages/ants/core/ants_image.py", line 583, in getitem return self._array.getitem(idx) IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

sj-choi commented 2 months ago

I also attempted it using ANTsRNet. It also stops.

============================================================================= The composite transform comprises the following transforms (in order):

  1. inverse of /tmp/RtmpjAFOzf/file13a22609ff590GenericAffine.mat (type = AffineTransform)

    Default pixel value: 0.0000e+00 Interpolation type: LinearInterpolateImageFunction Output warped image: 0x55aaa6039130 [1] "-d"
    [2] "3"
    [3] "-i"
    [4] "<pointer: 0x55a99bb71f40>"
    [5] "-o"
    [6] "<pointer: 0x55a9167c9560>"
    [7] "-r"
    [8] "<pointer: 0x55a90d9eea20>"
    [9] "-n"
    [10] "linear"
    [11] "-t"
    [12] "[/tmp/RtmpjAFOzf/file13a22609ff590GenericAffine.mat,1]" Using single precision for computations. Input scalar image: 0x55a99bb71f40 Reference image: 0x55a90d9eea20

    The composite transform comprises the following transforms (in order):

  2. inverse of /tmp/RtmpjAFOzf/file13a22609ff590GenericAffine.mat (type = AffineTransform)

    Default pixel value: 0.0000e+00 Interpolation type: LinearInterpolateImageFunction Output warped image: 0x55a9167c9560 Error in dkt_results$segmentationImage : $ operator not defined for this S4 class Calls: antsImageWrite -> check_ants Execution halted

ntustison commented 2 months ago

Around 9 gb for this tutorial example. But it looks like you're getting to the end and it's faulting on writing the results to disk. Are you sure it's happening during the actual dkt call?

sj-choi commented 2 months ago

Do you see any issues in the following that I used to perform DKT labeling?:

NOTE: 'scancode' is a subject ID in a for-loop to handle multiples subjects.

img1 = os.path.join(file_location, f"{scancode}_baseline_lesion_filled_T1W.nii.gz") print(img1) t1 = ants.image_read(img1)

DKT labeling

dkt = os.path.join(file_location, "ANTsPyNet_labels", f"{scancode}-DKT.nii.gz") if not os.path.exists(dkt): dkt_results = antspynet.desikan_killiany_tourville_labeling(t1, verbose=True) ants.image_write(dkt_results['segmentation_image'], dkt) else: print(f"{dkt} already exits.")


I did indentation properly. However, it looks like above after copy-and-past.

ntustison commented 2 months ago

Before I look at your code or explore your data, I need to be sure that you're able to run the corresponding tutorial example. Have you ran it and did it finish as expected?

sj-choi commented 2 months ago

Thank you, I will try it first.

sj-choi commented 2 months ago

dkt seemed to work on the example data in your tutorial link.

I processed the tutorial example image and the code worked well. I used the following code, which is very similar that I provided above:

!/usr/bin/env python3

import os import ants import antspynet

Example image

t1 = ants.image_read(antspynet.get_antsxnet_data('mprage_hippmapp3r'))

Save the example

file_location = "/home/xubuntu/Desktop/test"
print(file_location) t1_nii = os.path.join(file_location, "ANTsPyNet_tutorial", f"mprage_hippmapp3r.nii.gz") ants.image_write(t1, t1_nii)

Deep Atropos

seg = antspynet.deep_atropos(t1, verbose=True)

Save the Deep Atropos results.

seg_nii = os.path.join(file_location, "ANTsPyNet_tutorial", f"mprage_hippmapp3r-seg.nii.gz") ants.image_write(seg['segmentation_image'], seg_nii)

Deep DKT labeling

dkt = antspynet.desikan_killiany_tourville_labeling(t1, do_lobar_parcellation=True, verbose=True)

Save the DKT results.

dkt_nii = os.path.join(file_location, "ANTsPyNet_tutorial", f"mprage_hippmapp3r-DKT.nii.gz") ants.image_write(dkt['segmentation_image'], dkt_nii)

image

sj-choi commented 2 months ago

I'm uncertain whether this was the reason for the unsuccessful outcomes of the prior attempts at DKT labeling. Interestingly, the DKT labeling process was successful when I enabled the do_lobar_parcellation=True option. However, it failed to work when I didn't use this option.

ntustison commented 2 months ago

Are you discussing the tutorial example?

sj-choi commented 2 months ago

The tutorial example worked. I noticed that the option (do_lobar_parcellation=True) was used in the example and used it on my data, which worked. However, it did not work when I did not use the option.

ntustison commented 2 months ago

Did you try that scenario (do_lobar_parcellation=False) on the tutorial data?

ntustison commented 2 months ago

Closing as I can't reproduce the error. Reopen if necessary.