ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.2k stars 381 forks source link

Random seed seems to have no effect on ANTs with SyN and CC #1470

Closed gandreadis closed 1 year ago

gandreadis commented 1 year ago

Describe the problem

I'm using the ANTs antsRegistration CMD-line executable, with SyN as transform and CC as metric. I'm using the --random-seed option to set the value, but no matter what I set it (0, which should use system time, or any positive non-0 value, which should set that as seed), the output and metric/convergence values over time are always exactly the same. I've also tried the ANTS_RANDOM_SEED environment variable, but no success with this, either.

Following the wiki, I've also tried to specify a sampling strategy for CC (random with percentage [0-1]), but this does not change the result. I've used --verbose to verify that this sampling strategy is indeed set.

To Reproduce Use the antsRegistration script with two images, using the SyN transform with CC, and try to set the random seed with --random-seed [int].

System information (please complete the following information)

ANTs version information

Additional information

gdevenyi commented 1 year ago

Have you read https://github.com/ANTsX/ANTs/wiki/antsRegistration-reproducibility-issues

stnava commented 1 year ago

short story - this is expected as CC is not randomized

gandreadis commented 1 year ago

@stnava That explains it, thanks. Is it possible to use a different sampling strategy with CC? Or is CC always deterministic? Because in that case it might be good to mention this somewhere.

cookpa commented 1 year ago

This is a bit confusing because the metric sampling strategy is an option of the metric (eg, CC) in antsRegistration, but it's a property of the registration type (eg, Rigid, SyN) in ITK.

If you choose any sampling strategy other than "None", the registration method may use random sampling to choose and/or perturb the points. This leads to variation in results. But the SyN method doesn't do that.

You can make CC non-deterministic with another transform, eg -t Affine[0.1] -m CC[ fixed, moving, 1, Random, 0.5 ] will be non-deterministic, because the affine registration method calls ImageRegistrationMethodv4:SetMetricSamplePoints(). I don't know if any of the deformable methods do.

gandreadis commented 1 year ago

@cookpa Thanks for the elaboration, that makes it clear. Maybe something to this effect could be added to the respective wiki entries about reproducibility? Because I can't imagine being the only one to only use the SyN stage (without affine) and trying to set the random seed parameter.

cookpa commented 1 year ago

Yes, I will try to explain it better

cookpa commented 1 year ago

Update, I tried to improve the wiki page

https://github.com/ANTsX/ANTs/wiki/antsRegistration-reproducibility-issues

I looked at the code again and I think SyN is the only transform option that doesn't call PrepareRegistrationMethod, so I think it's the only method that won't produce any variation with random subsampling in the metric.