Commit 20b3fbca authored by Benoit Martin's avatar Benoit Martin

Merge branch 'master' of gitlab.icm-institute.org:aramislab/deformetrica

parents c9355d4c 9d8488dc
Pipeline #50174345 failed with stages
in 8 minutes and 44 seconds
-0.067755 0.000000 0.359551
0.559233 -0.000000 -0.003716
-0.422648 -0.080930 0.076706
-0.422648 0.080930 0.076706
0.353976 -0.319330 -0.076485
0.353976 0.319330 -0.076485
0.186280 -0.105913 0.136968
0.186280 0.105913 0.136968
0.073496 -0.042885 0.171005
0.073496 0.042885 0.171005
0.000894 -0.101015 0.219853
0.000894 0.101015 0.219853
-0.317115 -0.490302 -0.140880
-0.317115 0.490302 -0.140880
0.036356 -0.184840 0.059506
0.036356 0.184840 0.059506
0.679924 -0.284836 -0.185795
0.679924 0.284836 -0.185795
-0.902296 0.000000 -0.014790
-0.334173 -0.308304 -0.031703
-0.226906 -0.388018 -0.066442
0.238526 -0.495303 -0.175104
0.682336 -0.249117 -0.140847
-0.527435 -0.227159 0.105247
-0.915072 -0.285449 -0.084949
-0.588108 -0.384526 0.027498
-0.414261 -0.558083 -0.173693
-0.709628 -0.546197 -0.209069
-0.279147 -0.551078 -0.191796
-0.441742 -0.076167 0.091928
0.075077 -0.548552 -0.169267
0.151201 -0.086105 0.142655
-0.328035 -0.078527 0.130721
-0.188634 -0.160355 0.078191
-0.319349 -0.157333 -0.009561
-0.695544 -0.078103 0.082735
-0.207819 -0.264980 -0.018917
-0.186662 -0.497279 -0.102856
-0.031502 -0.481533 -0.063280
-0.101123 -0.565625 -0.138967
-0.954181 -0.098791 -0.046933
-0.448314 -0.217296 0.009549
-0.855668 -0.454036 -0.168054
-0.685034 -0.225247 0.059026
-0.191490 -0.085893 0.236090
-0.346289 -0.446491 -0.091096
-0.067786 -0.240685 0.033290
-0.570304 -0.563494 -0.181845
-0.099131 -0.373187 -0.019988
0.025641 -0.066250 0.220869
0.121040 -0.443556 -0.072552
-0.559714 -0.060168 0.126809
0.729400 -0.077894 -0.061917
-0.485049 -0.500588 -0.049254
0.054432 -0.163186 0.072704
-0.659303 -0.466641 -0.085426
-0.769765 -0.338041 -0.041579
-0.069767 -0.153351 0.179993
0.017718 -0.341852 0.005197
0.142156 -0.249748 0.025711
0.395681 -0.491973 -0.246075
0.585311 -0.050750 -0.005070
0.579522 -0.360325 -0.214198
0.375654 -0.398838 -0.122424
-0.077193 -0.080535 0.321587
-0.834540 -0.127215 0.002253
-0.445651 -0.371942 0.010079
0.584187 -0.166126 -0.056082
0.491718 -0.270257 -0.098930
-0.334173 0.308304 -0.031703
-0.226906 0.388018 -0.066442
0.238526 0.495303 -0.175104
0.682336 0.249117 -0.140847
-0.527435 0.227159 0.105247
-0.915072 0.285449 -0.084949
-0.588108 0.384526 0.027498
-0.414261 0.558083 -0.173693
-0.709628 0.546197 -0.209069
-0.279147 0.551078 -0.191796
-0.441742 0.076167 0.091928
0.075077 0.548552 -0.169267
0.151201 0.086105 0.142655
-0.328035 0.078527 0.130721
-0.188634 0.160355 0.078191
-0.319349 0.157333 -0.009561
-0.695544 0.078103 0.082735
-0.207819 0.264980 -0.018917
-0.186662 0.497279 -0.102856
-0.031502 0.481533 -0.063280
-0.101123 0.565625 -0.138967
-0.954181 0.098791 -0.046933
-0.448314 0.217296 0.009549
-0.855668 0.454036 -0.168054
-0.685034 0.225247 0.059026
-0.191490 0.085893 0.236090
-0.346289 0.446491 -0.091096
-0.067786 0.240685 0.033290
-0.570304 0.563494 -0.181845
-0.099131 0.373187 -0.019988
0.025641 0.066250 0.220869
0.121040 0.443556 -0.072552
-0.559714 0.060168 0.126809
0.729400 0.077894 -0.061917
-0.485049 0.500588 -0.049254
0.054432 0.163186 0.072704
-0.659303 0.466641 -0.085426
-0.769765 0.338041 -0.041579
-0.069767 0.153351 0.179993
0.017718 0.341852 0.005197
0.142156 0.249748 0.025711
0.395681 0.491973 -0.246075
0.585311 0.050750 -0.005070
0.579522 0.360325 -0.214198
0.375654 0.398838 -0.122424
-0.077193 0.080535 0.321587
-0.834540 0.127215 0.002253
-0.445651 0.371942 0.010079
0.584187 0.166126 -0.056082
0.491718 0.270257 -0.098930
0.244787 0.441660 -0.124611
0.224863 0.422926 -0.103295
0.203555 0.403002 -0.085167
0.181818 0.382468 -0.066610
0.160161 0.361466 -0.049455
0.138703 0.340243 -0.034386
0.116587 0.315975 -0.021148
0.093088 0.292328 -0.010644
0.068372 0.270062 -0.001130
0.043793 0.247639 0.008961
0.014743 0.229286 0.018403
0.244787 -0.441660 -0.124611
0.224863 -0.422926 -0.103295
0.203555 -0.403002 -0.085167
0.181818 -0.382468 -0.066610
0.160161 -0.361466 -0.049455
0.138703 -0.340243 -0.034386
0.116587 -0.315975 -0.021148
0.093088 -0.292328 -0.010644
0.068372 -0.270062 -0.001130
0.043793 -0.247639 0.008961
0.014743 -0.229286 0.018403
0.353943 0.318951 -0.076840
0.318176 0.310251 -0.052967
0.287520 0.294134 -0.022085
0.263653 0.270201 0.009325
0.248486 0.239857 0.040610
0.237599 0.206380 0.070680
0.228386 0.170062 0.097771
0.220138 0.131333 0.121548
0.221814 0.089184 0.140093
0.237727 0.046858 0.144191
0.240837 -0.000000 0.144112
0.353943 -0.318951 -0.076840
0.318176 -0.310251 -0.052967
0.287520 -0.294134 -0.022085
0.263653 -0.270201 0.009325
0.248486 -0.239857 0.040610
0.237599 -0.206380 0.070680
0.228386 -0.170062 0.097771
0.220138 -0.131333 0.121548
0.221814 -0.089184 0.140093
0.237727 -0.046858 0.144191
0.334994 0.290335 -0.060250
0.324017 0.260279 -0.038852
0.318330 0.233087 -0.011531
0.312891 0.206844 0.016592
0.306376 0.178270 0.042174
0.301065 0.146996 0.064662
0.297445 0.113434 0.083968
0.295181 0.078130 0.100250
0.293328 0.040664 0.110471
0.290482 0.000000 0.115974
0.334994 -0.290335 -0.060250
0.324017 -0.260279 -0.038852
0.318330 -0.233087 -0.011531
0.312891 -0.206844 0.016592
0.306376 -0.178270 0.042174
0.301065 -0.146996 0.064662
0.297445 -0.113434 0.083968
0.295181 -0.078130 0.100250
0.293328 -0.040664 0.110471
0.347914 0.280814 -0.061385
0.338580 0.251578 -0.040790
0.333526 0.224505 -0.015503
0.330611 0.199101 0.010933
0.326488 0.172047 0.036143
0.321941 0.142269 0.058237
0.318458 0.109138 0.075035
0.316637 0.073896 0.087151
0.318770 0.037204 0.092954
0.318747 -0.000000 0.093985
0.347914 -0.280814 -0.061385
0.338580 -0.251578 -0.040790
0.333526 -0.224505 -0.015503
0.330611 -0.199101 0.010933
0.326488 -0.172047 0.036143
0.321941 -0.142269 0.058237
0.318458 -0.109138 0.075035
0.316637 -0.073896 0.087151
0.318770 -0.037204 0.092954
0.383912 0.288495 -0.073772
0.401167 0.260743 -0.056703
0.416481 0.233230 -0.035661
0.427658 0.205483 -0.012845
0.433461 0.176582 0.010446
0.435967 0.146037 0.031846
0.436745 0.113498 0.048620
0.434922 0.078331 0.060200
0.432704 0.041414 0.067230
0.439201 0.000000 0.058410
0.383912 -0.288495 -0.073772
0.401167 -0.260743 -0.056703
0.416481 -0.233230 -0.035661
0.427658 -0.205483 -0.012845
0.433461 -0.176582 0.010446
0.435967 -0.146037 0.031846
0.436745 -0.113498 0.048620
0.434922 -0.078331 0.060200
0.432704 -0.041414 0.067230
-0.399426 0.601789 -0.253601
-0.434361 0.571336 -0.183510
-0.469967 0.544585 -0.115531
-0.504670 0.508180 -0.052334
-0.524224 0.452650 0.003085
-0.529609 0.384371 0.046803
-0.532440 0.309845 0.080466
-0.541850 0.233414 0.106686
-0.558825 0.155064 0.120583
-0.554692 0.074207 0.125803
-0.526166 0.000000 0.133583
-0.399426 -0.601789 -0.253601
-0.434361 -0.571336 -0.183510
-0.469967 -0.544585 -0.115531
-0.504670 -0.508180 -0.052334
-0.524224 -0.452650 0.003085
-0.529609 -0.384371 0.046803
-0.532440 -0.309845 0.080466
-0.541850 -0.233414 0.106686
-0.558825 -0.155064 0.120583
-0.554692 -0.074207 0.125803
<?xml version="1.0"?>
<data-set deformetrica-min-version="3.0.0">
</data-set>
<?xml version="1.0"?>
<model deformetrica-min-version="3.0.0">
<model-type>ParallelTransport</model-type>
<dimension>3</dimension>
<initial-control-points>data/GeodesicRegression__EstimatedParameters__ControlPoints.txt</initial-control-points>
<initial-momenta>data/GeodesicRegression__EstimatedParameters__Momenta.txt</initial-momenta>
<initial-momenta-to-transport>data/DeterministicAtlas__EstimatedParameters__Momenta.txt</initial-momenta-to-transport>
<template>
<object id="face">
<deformable-object-type>SurfaceMesh</deformable-object-type>
<attachment-type>Landmark</attachment-type>
<filename>data/human_scarred_to_happy_0.vtk</filename>
</object>
</template>
<deformation-parameters>
<kernel-width>0.005</kernel-width>
<concentration-of-timepoints>10</concentration-of-timepoints>
<kernel-type>torch</kernel-type>
<tmin>0</tmin>
<tmax>9</tmax>
</deformation-parameters>
</model>
<?xml version="1.0"?>
<optimization-parameters deformetrica-min-version="3.0.0">
</optimization-parameters>
......@@ -2,7 +2,7 @@
<data-set deformetrica-min-version="3.0.0">
<subject id="target">
<visit id="v0">
<filename object_id="brain">data/s0021_7960_8.nii</filename>
<filename object_id="brain">data/s0041_7110_0.nii</filename>
</visit>
</subject>
</data-set>
......@@ -8,14 +8,14 @@
<object id="brain">
<deformable-object-type>Image</deformable-object-type>
<filename>data/s0021_7260_0.nii</filename>
<noise-std>1</noise-std>
<noise-std>5e-2</noise-std>
</object>
</template>
<deformation-parameters>
<kernel-type>keops</kernel-type>
<kernel-width>10</kernel-width>
<number-of-timepoints>6</number-of-timepoints>
<number-of-timepoints>10</number-of-timepoints>
</deformation-parameters>
</model>
......@@ -3,8 +3,8 @@
<optimization-method-type>ScipyLBFGS</optimization-method-type>
<max-iterations>100</max-iterations>
<save-every-n-iters>100</save-every-n-iters>
<max-iterations>50</max-iterations>
<save-every-n-iters>10</save-every-n-iters>
<print-every-n-iters>1</print-every-n-iters>
<convergence-tolerance>1e-4</convergence-tolerance>
......
......@@ -13,7 +13,7 @@ from launch.estimate_longitudinal_atlas import estimate_longitudinal_atlas
from launch.estimate_longitudinal_metric_model import estimate_longitudinal_metric_model
from launch.estimate_longitudinal_metric_registration import estimate_longitudinal_metric_registration
from launch.estimate_longitudinal_registration import estimate_longitudinal_registration
from launch.run_shooting import run_shooting
from launch.compute_shooting import run_shooting
from support.utilities.general_settings import Settings
......
......@@ -127,7 +127,7 @@ class DeformableObjectReader:
nb_vertices = int(line[1])
assert int(line[2])/(dim + 1) == nb_vertices or \
(int(line[2])/(dim) == nb_vertices and line[0] == 'LINES'), \
'Should not happen, maybe invalid vtk file ?'
'Should not happen, maybe invalid vtk file or invalid dimension in model.xml ?'
break
else:
#print(filename, line)
......
......@@ -37,11 +37,13 @@ def compute_parallel_transport(xml_parameters):
control_points_torch = torch.from_numpy(control_points).type(Settings().tensor_scalar_type)
initial_momenta_torch = torch.from_numpy(initial_momenta).type(Settings().tensor_scalar_type)
initial_momenta_to_transport_torch = torch.from_numpy(initial_momenta_to_transport).type(Settings().tensor_scalar_type)
initial_momenta_to_transport_torch = torch.from_numpy(initial_momenta_to_transport).type(
Settings().tensor_scalar_type)
# We start by projecting the initial momenta if they are not carried at the reference progression control points.
if need_to_project_initial_momenta:
control_points_to_transport_torch = torch.from_numpy(control_points_to_transport).type(Settings().tensor_scalar_type)
control_points_to_transport_torch = torch.from_numpy(control_points_to_transport).type(
Settings().tensor_scalar_type)
velocity = kernel.convolve(control_points_torch, control_points_to_transport_torch,
initial_momenta_to_transport_torch)
kernel_matrix = kernel.get_kernel_matrix(control_points_torch)
......@@ -66,6 +68,9 @@ def _exp_parallelize(control_points, initial_momenta, projected_momenta, xml_par
template_points = {key: torch.from_numpy(value).type(Settings().tensor_scalar_type)
for key, value in template_points.items()}
template_data = template.get_data()
template_data = {key: torch.from_numpy(value).type(Settings().tensor_scalar_type)
for key, value in template_data.items()}
geodesic = Geodesic()
geodesic.concentration_of_time_points = xml_parameters.concentration_of_time_points
......@@ -91,7 +96,7 @@ def _exp_parallelize(control_points, initial_momenta, projected_momenta, xml_par
geodesic.update()
# We write the flow of the geodesic
geodesic.write("Regression", objects_name, objects_name_extension, template, template.get_data())
geodesic.write("Regression", objects_name, objects_name_extension, template, template_data)
# Now we transport!
parallel_transport_trajectory = geodesic.parallel_transport(projected_momenta)
......@@ -108,14 +113,14 @@ def _exp_parallelize(control_points, initial_momenta, projected_momenta, xml_par
exponential.set_use_rk2_for_shoot(True)
exponential.set_use_rk2_for_flow(xml_parameters.use_rk2_for_flow)
# We save the parallel trajectory
for i, (time, cp, mom, transported_mom) in enumerate(
zip(times, control_points_traj, momenta_traj, parallel_transport_trajectory)):
# Writing the momenta/cps
write_2D_array(cp.data.numpy(), "ControlPoints_tp_{0:d}__age_{1:.2f}.txt".format(i, time))
write_3D_array(mom.data.numpy(), "Momenta_tp_{0:d}__age_{1:.2f}.txt".format(i, time))
write_3D_array(transported_mom.data.numpy(), "Transported_Momenta_tp_{0:d}__age_{1:.2f}.txt".format(i, time))
write_2D_array(cp.detach().cpu().numpy(), "ControlPoints_tp_{0:d}__age_{1:.2f}.txt".format(i, time))
write_3D_array(mom.detach().cpu().numpy(), "Momenta_tp_{0:d}__age_{1:.2f}.txt".format(i, time))
write_3D_array(transported_mom.detach().cpu().numpy(),
"Transported_Momenta_tp_{0:d}__age_{1:.2f}.txt".format(i, time))
deformed_points = geodesic.get_template_points(time)
......@@ -125,14 +130,11 @@ def _exp_parallelize(control_points, initial_momenta, projected_momenta, xml_par
exponential.set_initial_momenta(transported_mom)
exponential.update()
parallel_points = exponential.get_template_points()
parallel_data = template.get_deformed_data(parallel_points, template.get_data())
parallel_data = template.get_deformed_data(parallel_points, template_data)
names = [
objects_name[k] + "_parallel_curve_tp_{0:d}__age_{1:.2f}".format(i, time) + objects_name_extension[k]
for k in range(len(objects_name))]
template.write(names, {key: value.data.cpu().numpy() for key, value in parallel_data.items()})
template.write(names, {key: value.detach().cpu().numpy() for key, value in parallel_data.items()})
......@@ -6,34 +6,34 @@ from in_out.dataset_functions import create_template_metadata
from support.utilities.general_settings import *
import torch
def run_shooting(xml_parameters):
def run_shooting(xml_parameters):
import logging
logger = logging.getLogger(__name__)
print('[ run_shooting function ]')
print('')
"""
Create the template object
"""
t_list, t_name, t_name_extension, t_noise_variance, multi_object_attachment = \
create_template_metadata(xml_parameters.template_specifications)
template = DeformableMultiObject()
template.object_list = t_list
template.update()
"""
Reading Control points and momenta
"""
if not xml_parameters.initial_control_points is None:
control_points = read_2D_array(xml_parameters.initial_control_points)
else:
raise ArgumentError('Please specify a path to control points to perform a shooting')
if not xml_parameters.initial_momenta is None:
momenta = read_3D_array(xml_parameters.initial_momenta)
else:
......@@ -41,11 +41,15 @@ def run_shooting(xml_parameters):
_, b = control_points.shape
assert Settings().dimension == b, 'Please set the correct dimension in the model.xml file.'
momenta_torch = torch.from_numpy(momenta)
control_points_torch = torch.from_numpy(control_points)
template_points = {key: torch.from_numpy(value).type(Settings().tensor_scalar_type) for key, value in template.get_points().items()}
momenta_torch = torch.from_numpy(momenta).type(Settings().tensor_scalar_type)
control_points_torch = torch.from_numpy(control_points).type(Settings().tensor_scalar_type)
template_points = {key: torch.from_numpy(value).type(Settings().tensor_scalar_type)
for key, value in template.get_points().items()}
template_data = {key: torch.from_numpy(value).type(Settings().tensor_scalar_type)
for key, value in template.get_data().items()}
geodesic = Geodesic()
......@@ -67,14 +71,15 @@ def run_shooting(xml_parameters):
else:
geodesic.tmin = xml_parameters.tmin
assert geodesic.tmax >= geodesic.t0, 'The max time {} for the shooting should be larger than t0 {}'\
assert geodesic.tmax >= geodesic.t0, 'The max time {} for the shooting should be larger than t0 {}' \
.format(geodesic.tmax, geodesic.t0)
assert geodesic.tmin <= geodesic.t0, 'The min time for the shooting should be lower than t0.'\
assert geodesic.tmin <= geodesic.t0, 'The min time for the shooting should be lower than t0.' \
.format(geodesic.tmin, geodesic.t0)
geodesic.set_control_points_t0(control_points_torch)
geodesic.concentration_of_time_points = xml_parameters.concentration_of_time_points
geodesic.set_kernel(kernel_factory.factory(xml_parameters.deformation_kernel_type, xml_parameters.deformation_kernel_width))
geodesic.set_kernel(
kernel_factory.factory(xml_parameters.deformation_kernel_type, xml_parameters.deformation_kernel_width))
geodesic.set_use_rk2_for_shoot(xml_parameters.use_rk2_for_shoot)
geodesic.set_use_rk2_for_flow(xml_parameters.use_rk2_for_flow)
geodesic.set_template_points_t0(template_points)
......@@ -84,7 +89,7 @@ def run_shooting(xml_parameters):
geodesic.set_momenta_t0(momenta_torch)
geodesic.update()
names = [elt for elt in t_name]
geodesic.write('Shooting', names, t_name_extension, template, template.get_data(),
geodesic.write('Shooting', names, t_name_extension, template, template_data,
write_adjoint_parameters=True)
# Several shootings to compute
......@@ -93,20 +98,5 @@ def run_shooting(xml_parameters):
geodesic.set_momenta_t0(momenta_torch[i])
geodesic.update()
names = [elt for elt in t_name]
geodesic.write('Shooting' + "_" + str(i), names, t_name_extension, template, template.get_data(),
geodesic.write('Shooting' + "_" + str(i), names, t_name_extension, template, template_data,
write_adjoint_parameters=True)
<?xml version="1.0"?>
<optimization-parameters deformetrica-min-version="3.0.0">
<use-rk2>On</use-rk2>
<use-rk2-for-shoot>On</use-rk2-for-shoot>
</optimization-parameters>
1 60 2
-0.011748183300368064 -0.016604688421522414
0.0025405589962937923 -0.06597769808287936
0.04174343542696522 -0.1083713168778814
0.06371027677160972 -0.026490772634068738
-0.0333048621655612 -0.1278743436636074
0.07432841410870968 -0.05991864116020652
-0.04800919257117421 -0.055244441554593966
0.051783320363692584 0.14430732530269805
0.03404332236151453 1.2320026262454333
-0.34044509650242266 0.9687340264171198
0.16171550593830603 0.37947833885867777
-0.1884181098028632 0.13461213490328314
0.03847940300760547 0.14653672831276063
-0.1088943814251311 0.04684169977282768
0.0011955493804251087 -0.014484067741119037
0.11953917217843837 0.07329659115809713
1.2038921232411144 0.9948537890373149
0.28319705965088376 2.4789620406104236
-0.01174818330036804 -0.016604688421522375
0.0025405589962937646 -0.06597769808287944
0.041743435426964945 -0.10837131687788126
0.06371027677161015 -0.026490772634068932
-0.03330486216556124 -0.1278743436636072
0.07432841410870959 -0.05991864116020644
-0.048009192571174225 -0.055244441554593925
0.05178332036369211 0.1443073253026979