%load_ext memory_profiler
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
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(
'/Users/arokem/source/dipy/doc/examples/lr-superiorfrontal.trk',
points_space='voxel')[0]]
Dataset is already in place. If you want to fetch it again, please first remove the folder /Users/arokem/.dipy/stanford_hardi All files already in /Users/arokem/.dipy/stanford_hardi.
candidate_sl = candidate_sl * 6
import dipy.tracking.life as life
fiber_model = life.FiberModel(gtab)
len(candidate_sl)
55188
for i in np.arange(0, 16):
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
/Users/arokem/anaconda3/envs/py2/lib/python2.7/site-packages/memory_profiler.py:68: UserWarning: psutil module not found. memory_profiler will be slow warnings.warn("psutil module not found. memory_profiler will be slow")
peak memory: 353.93 MiB, increment: 2.70 MiB Number of streamlines: 2 peak memory: 355.88 MiB, increment: 1.95 MiB Number of streamlines: 4 peak memory: 356.99 MiB, increment: 1.11 MiB Number of streamlines: 8 peak memory: 347.34 MiB, increment: 4.05 MiB Number of streamlines: 16 peak memory: 297.30 MiB, increment: 8.16 MiB Number of streamlines: 32 peak memory: 316.82 MiB, increment: 20.69 MiB Number of streamlines: 64 peak memory: 348.77 MiB, increment: 37.71 MiB Number of streamlines: 128 peak memory: 439.76 MiB, increment: 99.91 MiB Number of streamlines: 256 peak memory: 547.12 MiB, increment: 156.11 MiB Number of streamlines: 512 peak memory: 805.96 MiB, increment: 359.49 MiB Number of streamlines: 1024 peak memory: 1322.99 MiB, increment: 891.96 MiB Number of streamlines: 2048 peak memory: 2254.77 MiB, increment: 1688.54 MiB Number of streamlines: 4096 peak memory: 3012.15 MiB, increment: 2189.89 MiB Number of streamlines: 8192 peak memory: 4300.14 MiB, increment: 3414.67 MiB Number of streamlines: 16384 peak memory: 4553.35 MiB, increment: 3113.25 MiB Number of streamlines: 32768 peak memory: 4592.92 MiB, increment: 1854.17 MiB
m = [353.93, 355.88, 356.99, 347.34, 297.30, 316.82, 348.77,
439.76, 547.12, 805.96, 1322.99, 2254.77, 3012.15, 4300.14, 4553.35, 4592.92]
fig, ax = plt.subplots()
ax.plot(2 ** np.arange(16), m, 'o-')
ax.set_ylabel('Memory usage (MiB)')
ax.set_xlabel('# streamlines')
p = np.polyfit(2 ** np.arange(16), m, 1)