ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.15k stars 374 forks source link

Segmentation Fault during SyN registration #508

Closed david-hoffman closed 4 years ago

david-hoffman commented 6 years ago

I'm getting a segmentation fault when running antsRegistrationSyNQuick.sh. The actual call I use is:

antsRegistrationSyNQuick.sh -d 3 -f PALM_488nm_Hist_Trans.nii -m Mitos3_closing.nii -o "EMtoLM_Hist" -n 8 -p f

The segmentation fault itself occurs during the 3rd level of the second stage (the SyN stage).

Here's some output immediately preceding the error.

...
Stage 2
iterations = 100x100x70x50x0
convergence threshold = 1.0000e-06
convergence window size = 10
number of levels = 5
using the Mattes MI metric (number of bins = 32, weight = 1.0000e+00)
preprocessing:  winsorizing the image intensities
Shrink factors (level 1 out of 5): [10, 10, 3]
Shrink factors (level 2 out of 5): [6, 6, 2]
Shrink factors (level 3 out of 5): [4, 4, 1]
Shrink factors (level 4 out of 5): [2, 2, 1]
Shrink factors (level 5 out of 5): [1, 1, 1]
smoothing sigmas per level: [5, 3, 2, 1, 0]
Using default NONE metricSamplingStrategy
*** Running SyN registration (varianceForUpdateField = 3.0000e+00, varianceForTotalField = 0.0000e+00) ***
XXDIAGNOSTIC,Iteration,metricValue,convergenceValue,ITERATION_TIME_INDEX,SINCE_LAST 
... (level 3) ...
 1DIAGNOSTIC,    70, -7.606014609337e-03, 6.114590178186e-06, 2.2912e+04, 2.6768e+02,
/home/hoffmand/bin/ants/bin/antsRegistrationSyNQuick.sh: line 581:  6667 Segmentation fault      (core dumped) $COMMAND 

This is the actual call that the script generates and executes:

/home/hoffmand/bin/ants/bin//antsRegistration --verbose 1 --dimensionality 3 --float 1 --collapse-output-transforms 1 --output [EMtoLM_Hist,EMtoLM_HistWarped.nii.gz,EMtoLM_HistInverseWarped.nii.gz] --interpolation Linear --use-histogram-matching 0 --winsorize-image-intensities [0.005,0.995] --initial-moving-transform [PALM_488nm_Hist_Trans.nii,Mitos3_closing.nii,1] --transform Rigid[0.1] --metric MI[PALM_488nm_Hist_Trans.nii,Mitos3_closing.nii,1,32,Regular,0.25] --convergence [1000x500x250x0,1e-6,10] --shrink-factors 12x8x4x2 --smoothing-sigmas 4x3x2x1vox --transform Affine[0.1] --metric MI[PALM_488nm_Hist_Trans.nii,Mitos3_closing.nii,1,32,Regular,0.25] --convergence [1000x500x250x0,1e-6,10] --shrink-factors 12x8x4x2 --smoothing-sigmas 4x3x2x1vox --transform SyN[0.1,3,0] --metric MI[PALM_488nm_Hist_Trans.nii,Mitos3_closing.nii,1,32] --convergence [100x100x70x50x0,1e-6,10] --shrink-factors 10x6x4x2x1 --smoothing-sigmas 5x3x2x1x0vox

I've run this on much smaller volumes with success so it maybe that the computer is running out of memory, I'm not sure if this would cause a segmentation fault.

Is there anyway process data our of core if it's too large? Is there a way to test/estimate memory usage?

ntustison commented 6 years ago

so it maybe that the computer is running out of memory

I'm guessing this is the case. For the SyN step, a total of four displacement fields are created for the optimization process and each displacement field voxel contains x, y, and z components so you can see how this could be prohibitive in terms of memory for large images.

If this is the case then you could 1) try using a different deformable transform or 2) downsample your input images and then upsample the resulting displacement fields following registration. If it were me, I would tend towards the latter but both of those are possible choices.

david-hoffman commented 6 years ago

For the later method is it possible to have ANTs do the downsampling and upsampling internally? Maybe using shrink factors greater than 1?

ntustison commented 6 years ago

You can try that but you have to make sure that the last downsampling factor for that transform is 1 even if it is paired with a 0 for the number of iterations.

david-hoffman commented 6 years ago

Why is that?

david-hoffman commented 6 years ago

@ntustison I tried your suggestion and it still results in a segmentation fault even with 0 iterations :sob:.

Stage 2
iterations = 100x100x0
convergence threshold = 1.0000e-06
convergence window size = 10
number of levels = 3
using the Mattes MI metric (number of bins = 32, weight = 1.0000e+00)
preprocessing:  winsorizing the image intensities
Shrink factors (level 1 out of 3): [10, 10, 3]
Shrink factors (level 2 out of 3): [6, 6, 2]
Shrink factors (level 3 out of 3): [1, 1, 1]
smoothing sigmas per level: [5, 3, 1]
Using default NONE metricSamplingStrategy
*** Running SyN registration (varianceForUpdateField = 3.0000e+00, varianceForTotalField = 0.0000e+00) *** 
stnava commented 6 years ago

I don’t think you should set a full resolution level

Instead just remove the last level entirely

On Sat, Oct 14, 2017 at 4:56 PM David Hoffman notifications@github.com wrote:

@ntustison https://github.com/ntustison I tried your suggestion and it still results in a segmentation fault even with 0 iterations :'(.

Stage 2 iterations = 100x100x0 convergence threshold = 1.0000e-06 convergence window size = 10 number of levels = 3 using the Mattes MI metric (number of bins = 32, weight = 1.0000e+00) preprocessing: winsorizing the image intensities Shrink factors (level 1 out of 3): [10, 10, 3] Shrink factors (level 2 out of 3): [6, 6, 2] Shrink factors (level 3 out of 3): [1, 1, 1] smoothing sigmas per level: [5, 3, 1] Using default NONE metricSamplingStrategy Running SyN registration (varianceForUpdateField = 3.0000e+00, varianceForTotalField = 0.0000e+00)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTs/issues/508#issuecomment-336666922, or mute the thread https://github.com/notifications/unsubscribe-auth/AATyfsjwuTlcyg2TfskxJ_mSC8wqnFu4ks5ssR_wgaJpZM4P4tgC .

--

brian

david-hoffman commented 6 years ago

@stnava I tried running without the last full resolution level, but the output warped images and my attempts to use antsApplyTransforms results in improperly warped images. They look like some deformation has been applied, but that the linear transformation has not been. If I leave in the last resolution step then everything works correctly.

stnava commented 6 years ago

lets work with repeatable examples that are easy to run/verify.

https://github.com/stnava/cars

run this

antsRegistrationSyNQuick.sh -d 2 -f ~/data/antsExamples/cars/beetle.jpg -m ~/data/antsExamples/cars/ford.jpg -t s -o /tmp/ARSE

​modify the command line to remove extra levels - and see that it works as expected ( this functionality has been around for some time )

antsRegistration --verbose 1 --dimensionality 2 --float 0 --output [/tmp/ARSE,/tmp/ARSEWarped.nii.gz,/tmp/ARSEInverseWarped.nii.gz] --interpolation Linear --use-histogram-matching 0 --winsorize-image-intensities [0.005,0.995] --initial-moving-transform [~/data/antsExamples/cars/beetle.jpg,~/data/antsExamples/cars/ford.jpg,1] --transform Rigid[0.1] --metric MI[~/data/antsExamples/cars/beetle.jpg,~/data/antsExamples/cars/ford.jpg,1,32,Regular,0.25] --convergence [1000x500x250,1e-6,10] --shrink-factors 12x8x4 --smoothing-sigmas 4x3x2vox --transform Affine[0.1] --metric MI[~/data/antsExamples/cars/beetle.jpg,~/data/antsExamples/cars/ford.jpg,1,32,Regular,0.25] --convergence [1000x500x250x0,1e-6,10] --shrink-factors 12x8x4x2 --smoothing-sigmas 4x3x2x1vox --transform SyN[0.1,3,0] --metric MI[~/data/antsExamples/cars/beetle.jpg,~/data/antsExamples/cars/ford.jpg,1,32] --convergence [100x100x70,1e-6,10] --shrink-factors 10x6x4 --smoothing-sigmas 5x3x2vox​

​whether the result is "good" or not is up to a matter of quantitative validation which only you can determine for your problem.​

On Fri, Jan 12, 2018 at 4:36 PM, David Hoffman notifications@github.com wrote:

@stnava https://github.com/stnava I tried running without the last full resolution level, but the output warped images and my attempts to use antsApplyTransforms results in improperly warped images. They look like some deformation has been applied, but that the linear transformation has not been. If I leave in the last resolution step then everything works correctly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTs/issues/508#issuecomment-357361084, or mute the thread https://github.com/notifications/unsubscribe-auth/AATyfqbQYgdQ-A0nbkRdmIQiQQP5J4n3ks5tJ9BsgaJpZM4P4tgC .

david-hoffman commented 6 years ago

@stnava the test worked fine