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

Atropos - Error when using 3 class tissue segmentation #1765

Closed
grahamlittlephd opened this issue Jul 3, 2024 · 19 comments
Closed

Atropos - Error when using 3 class tissue segmentation #1765

grahamlittlephd opened this issue Jul 3, 2024 · 19 comments
Labels
bug Reproducible bugs

Comments

@grahamlittlephd
Copy link

Operating system and version

Ubuntu 22.04

CPU architecture

x86_64 (PC, Intel Mac, other Intel/AMD)

ANTs code version

2.5.2

ANTs installation type

Downloaded Github release binaries

Summary of the problem

Getting the following error when running a 3 class tissue segmentation of the hippocampus/amygdala.

Progress:
WARNING: In /home/runner/work/ANTs/ANTs/ImageSegmentation/antsHistogramParzenWindowsListSampleFunction.hxx, line 57
HistogramParzenWindowsListSampleFunction (0x55a3c60883d0): The input list sample has <= 1 element.Function evaluations will be equal to 0.

Iteration 0 (of 5): posterior probability = 0 (annealing temperature = 1)

itk::ExceptionObject (0x55a3c60b8cf0)
Location: "unknown"
File: /home/runner/work/_temp/build/staging/include/ITK-5.4/itkLabelMap.hxx
Line: 180
Description: ITK ERROR: LabelMap(0x55a3c6f42450): Can't access label object at position 2. The label map has only 2 label objects registered

Seems to work with v2.3.5.post76-g28dd25c

Note if I change the number of classes to 2, without changing any other input the command works

Commands to reproduce the problem.

Atropos -a 122317_b0b1000_MD_plusFA.nii.gz -x 122317_initialization_LEFT_HIPPOAMYG.nii.gz -i PriorProbabilityImages[3,122317_initialization_INITAMYGHIPPO_LH_%02d.nii.gz,0.3,0.0001] -m [0.3, 2x2x2] --use-partial-volume-likelihoods false -s 1x3 -s 1x2 -o [122317_initialization_INITAMYGHIPPO_LH_LABELS.nii.gz, 122317_initialization_INITAMYGHIPPO_LH_PROBS_%02d.nii.gz] -k HistogramParzenWindows[1.0,32] -v 1

Output of the command with verbose output.

"""Atropos -a 122317_b0b1000_MD_plusFA.nii.gz -x 122317_initialization_LEFT_HIPPOAMYG.nii.gz -i PriorProbabilityImages[3,122317_initialization_INITAMYGHIPPO_LH_%02d.nii.gz,0.3,0.0001] -m [0.3, 2x2x2] --use-partial-volume-likelihoods false -s 1x3 -s 1x2 -o [122317_initialization_INITAMYGHIPPO_LH_LABELS.nii.gz, 122317_initialization_INITAMYGHIPPO_LH_PROBS_%02d.nii.gz] -k HistogramParzenWindows[1.0,32] -v 1

Running Atropos for 3-dimensional images.

Progress:
WARNING: In /home/runner/work/ANTs/ANTs/ImageSegmentation/antsHistogramParzenWindowsListSampleFunction.hxx, line 57
HistogramParzenWindowsListSampleFunction (0x55a3c60883d0): The input list sample has <= 1 element.Function evaluations will be equal to 0.

Iteration 0 (of 5): posterior probability = 0 (annealing temperature = 1)

itk::ExceptionObject (0x55a3c60b8cf0)
Location: "unknown"
File: /home/runner/work/_temp/build/staging/include/ITK-5.4/itkLabelMap.hxx
Line: 180
Description: ITK ERROR: LabelMap(0x55a3c6f42450): Can't access label object at position 2. The label map has only 2 label objects registered."""

Data to reproduce the problem

atropos_hippoamyg_seg.zip

You should be able to run the command from the inside the directory in the zip

@cookpa
Copy link
Member

cookpa commented Jul 3, 2024

Thanks for the command and data. I think the problem is that there are zero voxels with label 3 in the segmentation. If I dilate the mask, it works for me.

@grahamlittlephd
Copy link
Author

Thanks so much for the quick reply, I am trying to get some scripts updated to work with the newest version of ants.
So am I correct that this was acceptable in a previous version (2.3.5) but now in 2.5.2, if a label doesn't exist in the output for all classes Atropos will error.

Maybe this should addressed as a bug for fixing or detailed somewhere in the documentation

@cookpa
Copy link
Member

cookpa commented Jul 3, 2024

There was a bug in the parzen window code where it would fail if multi-threaded, so if you run 2.3.5 to check, use one thread.

I'll build 2.3.5 and check in a bit

@grahamlittlephd
Copy link
Author

Thanks, something I forgot to mention, I can reproduce the error in 2.5.2 when I remove the parzen window option and just use defaults. Just an FYI incase you are testing.

@cookpa
Copy link
Member

cookpa commented Jul 3, 2024

Thanks, yes I switched to Gaussian to avoid that other bug. I couldn't build 2.3.5 but I was able to run the binaries for 2.4.1, and it works. Will track down the release where this occurs.

@cookpa cookpa added the bug Reproducible bugs label Jul 3, 2024
@cookpa
Copy link
Member

cookpa commented Jul 3, 2024

OK, it works with 2.5.1 but not 2.5.2.

@ntustison, would you mind taking a look when you have time? The simplified command I was running with the example data above:

Atropos -a 122317_b0b1000_MD_plusFA.nii.gz -x 122317_initialization_LEFT_HIPPOAMYG.nii.gz -i PriorProbabilityImages[3,122317_initialization_INITAMYGHIPPO_LH_%02d.nii.gz,0.3,0.0001] -m [0.3, 2x2x2] -o [122317_initialization_INITAMYGHIPPO_LH_LABELS.nii.gz, 122317_initialization_INITAMYGHIPPO_LH_PROBS_%02d.nii.gz] -k Gaussian -v 1

It works on 2.5.1 but with 2.5.2, it gives this error

Running Atropos for 3-dimensional images.

Progress: 
WARNING: In /Users/runner/work/ANTs/ANTs/ImageSegmentation/antsGaussianListSampleFunction.hxx, line 106
GaussianListSampleFunction (0x600003704300): The input list sample has <= 1 element.  Function evaluations will be equal to 0.

  Iteration 0 (of 5): posterior probability = 0 (annealing temperature = 1)

itk::ExceptionObject (0x6000028083a0)
Location: "unknown" 
File: /Users/runner/work/_temp/build/staging/include/ITK-5.4/itkLabelMap.hxx
Line: 181
Description: ITK ERROR: LabelMap(0x7f7da5709190): Can't access label object at position 2. The label map has only 2 label objects registered.

@gdevenyi
Copy link
Contributor

gdevenyi commented Jul 3, 2024

Could try a git bisect to find the exact commit which did it.

@ntustison
Copy link
Member

You're setting up your initial partitioning of the masked region with the three probability images (I'm guessing 1: amygdala, 2: hippocampus, and 3: cortex. Just probing the values in the mask, it would appear to me that no voxels are being assigned to the third label because one or both of the probabilities of the first two labels for all the voxels in the mask are greater than the corresponding probabilities of the third. Did you check that this isn't the case?

@cookpa
Copy link
Member

cookpa commented Jul 3, 2024

it would appear to me that no voxels are being assigned to the third label because one or both of the probabilities of the first two labels for all the voxels in the mask are greater than the corresponding probabilities of the third.

That is what's happening, yes. But this did not cause an error in ANTs 2.5.1 and earlier. Earlier versions did produce the warning

WARNING: In /Users/runner/work/ANTs/ANTs/ImageSegmentation/antsGaussianListSampleFunction.hxx, line 106
GaussianListSampleFunction (0x600003704300): The input list sample has <= 1 element.  Function evaluations will be equal to 0.

but then ran successfully. The output posteriors for class 3 were very small, and there were no class 3 labels in the output, but it didn't exit with the error.

@ntustison
Copy link
Member

If this is that degenerate case, it shouldn't go past initialization because the distribution for the third label is unknown without any representative samples. Perhaps a better use of time would be a check and a better explanation of the error, rather than tracking down why it "worked" before. Although if i had to guess, it is probably due to keeping the sample list around and some check that I'm doing.

@ntustison
Copy link
Member

Okay @cookpa , see if the above proposed solution works for you. I did a brief look to figure out why it worked before but I didn't see anything obvious.

@cookpa
Copy link
Member

cookpa commented Jul 4, 2024

Thanks @ntustison

@grahamlittlephd I think @ntustison is correct that it's better to error in this situation because the algorithm updates based on voxels labeled as a class, not just voxels with a non-zero prior probability.

Maybe it would make sense to extend the ROI or maybe even have a separate ROI representing cortex, so that Atropos has some sense of what cortex looks like

@ntustison
Copy link
Member

Related a bit---@grahamlittlephd, are you interested in segmenting the amygdala and hippocampus? If so, I can point you to functionality in our deep learning library which does this.

@grahamlittlephd
Copy link
Author

Thanks so much for looking into this! I agree that raising an error at least prevents the user from getting into this situation.

However, this still doesn't explain why the behavior of Atropos changed from 2.5.1 to 2.5.2. In 2.5.1 I always would get 3-classes in my output even if there are only a few voxels in label 3 (cortex). I have ran this command on at least 500 subjects. Now in version 2.5.2 there are only 2-classes in my output and the error was thrown.

I realize this is very much an edge case but you may want to consider finding the commit that did it like @gdevenyi mentioned, otherwise are you sure that this version update didn't effect other ants tools?

@grahamlittlephd
Copy link
Author

Related a bit---@grahamlittlephd, are you interested in segmenting the amygdala and hippocampus? If so, I can point you to functionality in our deep learning library which does this.

Very cool didn't know this existed. Not for this project but will add for something to try out at some point 👍

@ntustison
Copy link
Member

However, this still doesn't explain why the behavior of Atropos changed from 2.5.1 to 2.5.2.

It shouldn't have worked. I don't know exactly why it did. I have my hunches but, as I mentioned above, it's not worth my time to go back and investigate.

otherwise are you sure that this version update didn't effect other ants tools?

I can't guarantee that it didn't but I highly doubt that it did.

@cookpa
Copy link
Member

cookpa commented Jul 9, 2024

We should have better automated regression testing but I think the sampling updates are good, I ran

Atropos -d 3 -a tpl-MNI152NLin6Asym_res-02_T1w.nii.gz -x mask.nii.gz -i PriorProbabilityImages[3,prior%i.nii.gz,0.25] -k Gaussian -m [0.1, 1x1x1] -r 0 -c [5, 0] -o [2.5.2/threeTissueSeg.nii.gz, 2.5.2/threeTissueProb%i.nii.gz] --verbose

which produces identical results on 2.5.2, 2.5.1, 2.4.1.

@ntustison
Copy link
Member

Thanks for checking @cookpa. Is there anything outstanding for this issue or can we close it?

@cookpa
Copy link
Member

cookpa commented Jul 9, 2024

I think we can close this. Sorry this solution is not very convenient @grahamlittlephd, but Atropos was not intended to run when one of the classes is not present inside the mask.

@cookpa cookpa closed this as completed Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible bugs
Projects
None yet
Development

No branches or pull requests

4 participants