In [1]:
%load_ext memory_profiler
In [2]:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
In [3]:
from dipy.data import read_stanford_labels
import nibabel as nib
hardi_img, gtab, labels_img = read_stanford_labels()
data = hardi_img.get_data()
candidate_sl = [s[0] for s in nib.trackvis.read('./probabilistic_small_sphere.trk', points_space='voxel')[0]]
Dataset is already in place. If you want to fetch it again, please first remove the folder /home/arokem/.dipy/stanford_hardi 
All files already in /home/arokem/.dipy/stanford_hardi.
In [4]:
import dipy.tracking.life as life
fiber_model = life.FiberModel(gtab)
In [5]:
len(candidate_sl)
Out[5]:
2435680
In [6]:
for i in np.arange(0, 19):
    this = 2 ** i
    print("Number of streamlines: %s"%this)
    %memit fiber_fit = fiber_model.fit(data, candidate_sl[:this], affine=np.eye(4))
Number of streamlines: 1
peak memory: 3261.71 MiB, increment: 0.59 MiB
Number of streamlines: 2
peak memory: 3261.73 MiB, increment: 0.00 MiB
Number of streamlines: 4
peak memory: 3261.75 MiB, increment: 0.02 MiB
Number of streamlines: 8
peak memory: 3261.75 MiB, increment: 0.00 MiB
Number of streamlines: 16
peak memory: 3261.76 MiB, increment: 0.01 MiB
Number of streamlines: 32
peak memory: 3261.76 MiB, increment: 0.00 MiB
Number of streamlines: 64
peak memory: 3261.76 MiB, increment: 0.00 MiB
Number of streamlines: 128
peak memory: 3261.76 MiB, increment: 0.00 MiB
Number of streamlines: 256
peak memory: 3261.76 MiB, increment: 0.00 MiB
Number of streamlines: 512
peak memory: 3261.76 MiB, increment: 0.00 MiB
Number of streamlines: 1024
peak memory: 3261.76 MiB, increment: 0.00 MiB
Number of streamlines: 2048
peak memory: 3276.14 MiB, increment: 14.38 MiB
Number of streamlines: 4096
peak memory: 3321.05 MiB, increment: 44.91 MiB
Number of streamlines: 8192
peak memory: 3414.68 MiB, increment: 93.63 MiB
Number of streamlines: 16384
peak memory: 3617.24 MiB, increment: 202.57 MiB
Number of streamlines: 32768
peak memory: 4721.73 MiB, increment: 1281.57 MiB
Number of streamlines: 65536
peak memory: 8826.69 MiB, increment: 4939.83 MiB
Number of streamlines: 131072
peak memory: 20247.30 MiB, increment: 14472.56 MiB
Number of streamlines: 262144
peak memory: 55127.31 MiB, increment: 43989.15 MiB
In [9]:
m = [3261.71, 3261.73, 3261.75, 3261.76, 3261.76, 3261.76,
     3261.76, 3261.76, 3261.76, 3261.76, 3261.76, 3276.14,
     3321.05, 3414.68, 3617.24, 4721.73, 8826.69, 20247.30, 55127.31]     
In [10]:
fig, ax = plt.subplots()
ax.plot(2 ** np.arange(19), m, 'o-')
ax.set_ylabel('Memory usage (MiB)')
ax.set_xlabel('# streamlines')
Out[10]:
<matplotlib.text.Text at 0x2578ded0>
In [ ]: