import numpy as np
import menpo
from menpo.transform.piecewiseaffine.base import PythonPWA, CachedPWA, CythonPWA
b = menpo.io.import_builtin_asset('breakingbad.jpg')
b.crop_to_landmarks_proportion_inplace(0.1)
b.constrain_mask_to_landmarks()
points = b.mask.true_indices
src = b.landmarks['PTS'][None]
tgt = src.copy()
python_pwa = PythonPWA(src, tgt)
cached_pwa = CachedPWA(src, tgt)
cython_pwa = CythonPWA(src, tgt)
%matplotlib inline
b.view()
<menpo.visualize.viewmatplotlib.MatplotlibImageViewer2d at 0x7f2bf3f46f10>
%time x = python_pwa.apply(points)
CPU times: user 364 ms, sys: 116 ms, total: 480 ms Wall time: 479 ms
%time x = cached_pwa.apply(points)
CPU times: user 311 ms, sys: 146 ms, total: 457 ms Wall time: 457 ms
%time x = cython_pwa.apply(points)
CPU times: user 149 ms, sys: 573 µs, total: 150 ms Wall time: 149 ms
%timeit python_pwa.apply(points)
1 loops, best of 3: 453 ms per loop
%timeit cached_pwa.apply(points)
100 loops, best of 3: 12.7 ms per loop
%timeit cython_pwa.apply(points)
10 loops, best of 3: 22.3 ms per loop
np.all(cython_pwa.apply(points) == cached_pwa.apply(points))
True
np.all(python_pwa.apply(points) == cached_pwa.apply(points))
True