-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Following the presentation of @marinebcht yesterday, I tried to look more into the code today. 🕵️
@belletva @adebardo @adehecq
First, the cause is certainly not the early preprocess step during fit(), because this step is exactly the same for all methods.
That leaves the underlying registration algorithm functions, which are composed of 2 steps for each: A _preprocess_subsample step (yes, there are 2 internal preprocess 😅, I'm actually renaming the second into just _subsample for clarity in #759), and the _iterate_method step, which has different inputs/outputs for each method but relies on the same core function.
To explain the large difference in memory usage between LZD/ICP/CPD and NK/DM/VS, a likely culprit could be the respective preprocess-subsample step in each method, as there are 2 slightly different versions of it:
- The
_preprocess_rst_pts_subsamplefunction (example here) is used only in LZD/ICP/CPD, and also in VS (VerticalShift), - The
_preprocess_rst_pts_subsample_interpolator(example here that is used in NK/DM).
However, if I remember correctly, VerticalShift did not have large RAM usage, like NK/DM? If so, then this is probably not the right culprit, as it uses the same faction...
Another factor could be that the _preprocess_subsample step can accept auxiliary variables, which might create more memory usage. But, while auxiliary variables exist in the case of LZD/ICP, they don't in the case of CPD. So probably not that either...
The last step is _iterate_method, which is used by all iterative methods (NK, LZD, ICP, CPD). The only difference here between NK and LZD/ICP/CPD is the fact that NK only applies a translation to the data during iteration (normally, no additional memory usage once the interpolator is created), while LZD/ICP/CPD all apply a translation+rotation. Then they perform a similar optimization.
I manually checked the apply_matrix subfunction utilized here, and memory usage is very small for the subsample size we have (500,000):
import xdem
import numpy as np
test_pc = np.ones((3, 500000), dtype=np.float32)
matrix = xdem.coreg.matrix_from_translations_rotations(2, 3, 4, 5, 6, 7)
new_pc = xdem.coreg.base._apply_matrix_pts_mat(test_pc, matrix=matrix)All of this points towards the fact that the culprit is likely not the _iterate_method, but _preprocess_subsample, but it's unclear why VerticalShift wouldn't be affected...