%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.
import dipy.tracking.life as life
fiber_model = life.FiberModel(gtab)
for i in np.arange(0, 14):
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.95 MiB, increment: 2.66 MiB Number of streamlines: 2 peak memory: 355.89 MiB, increment: 1.93 MiB Number of streamlines: 4 peak memory: 355.79 MiB, increment: -0.09 MiB Number of streamlines: 8 peak memory: 346.62 MiB, increment: 4.06 MiB Number of streamlines: 16 peak memory: 297.62 MiB, increment: 9.21 MiB Number of streamlines: 32 peak memory: 316.05 MiB, increment: 20.67 MiB Number of streamlines: 64 peak memory: 347.95 MiB, increment: 37.66 MiB Number of streamlines: 128 peak memory: 442.94 MiB, increment: 103.92 MiB Number of streamlines: 256 peak memory: 546.53 MiB, increment: 156.33 MiB Number of streamlines: 512 peak memory: 805.21 MiB, increment: 359.52 MiB Number of streamlines: 1024 peak memory: 1322.86 MiB, increment: 892.62 MiB Number of streamlines: 2048 peak memory: 2107.50 MiB, increment: 1541.49 MiB Number of streamlines: 4096 peak memory: 3229.17 MiB, increment: 2586.12 MiB Number of streamlines: 8192 peak memory: 4551.69 MiB, increment: 3649.34 MiB
m = [353.95, 355.89, 355.79, 346.62, 297.62, 316.05, 347.95,
442.94, 546.53, 805.21, 1322.86, 2107.50, 3229.17, 4551.69]
fig, ax = plt.subplots()
ax.plot(2 ** np.arange(14), m, 'o-')
ax.set_ylabel('Memory usage (MiB)')
ax.set_xlabel('# streamlines')
p = np.polyfit(2 ** np.arange(14), m, 1)
xx = np.linspace(0, 10000, 2)
ax.plot(xx, np.polyval(p, xx), '--')
[<matplotlib.lines.Line2D at 0x114b33ed0>]
fig, ax = plt.subplots()
ax.set_ylabel('Memory usage (MiB)')
ax.set_xlabel('# streamlines')
xx = np.linspace(0, 1000000, 2)
ax.plot(xx, np.polyval(p, xx), '--')
[<matplotlib.lines.Line2D at 0x114a3eb50>]