In [1]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib

Load data


In [2]:
import menpo.io as mio
from menpo.landmark import labeller, ibug_face_49
from menpofast.utils import convert_from_menpo

path = '/data/'
group = 'ibug_face_49'
db = 'afw'

test_images = []
for i in mio.import_images(path + 'PhD/DataBases/faces/' + db, 
                           verbose=True, max_images=1):
    
    # convert the image from menpo Image to menpofast Image (channels at front)
    i = convert_from_menpo(i)
    
    labeller(i, 'PTS', eval(group))
    i.crop_to_landmarks_proportion_inplace(0.5, group='PTS')
    i = i.rescale_landmarks_to_diagonal_range(150, group=group)
    
    if i.n_channels == 3:
        i = i.as_greyscale(mode='average')
    test_images.append(i)


- Loading 1 assets: [====================] 100%

Parts AAMs


In [3]:
from menpofast.feature import no_op, fast_dsift
from alabortijcv2015.utils import pickle_load

aam_type = 'PartsAAM'
features = fast_dsift

aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_' + aam_type + '_' + features.__name__ )

Fitting parameters


In [4]:
from alabortijcv2015.aam.algorithm import SIC

algorithm_cls = SIC

sampling_step = 7

sampling_mask = np.require(np.zeros((17, 17)), dtype=np.bool)
sampling_mask[1::sampling_step, 1::sampling_step] = True

n_shape = [3, 12]
n_appearance = [25, 50]

noise_std = 0.04
max_iters = 20
prior = False

imshow(sampling_mask)


Out[4]:
<matplotlib.image.AxesImage at 0x7f00adc7ead0>

Run times

Simultaneous Algorithms

SIC


In [5]:
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import SIC

algorithm_cls = SIC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 151 ms per loop

SICN


In [6]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SICN

algorithm_cls = SICN

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 454 ms per loop

SFC


In [7]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SFC

algorithm_cls = SFC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 152 ms per loop

SFCN


In [8]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SFCN

algorithm_cls = SFCN

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 452 ms per loop

SSC


In [9]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SSC

algorithm_cls = SSC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 227 ms per loop

SBC


In [92]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import SBC

algorithm_cls = SBC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 289 ms per loop

Alternating Algorithms

AIC


In [94]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AIC

algorithm_cls = AIC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


10 loops, best of 3: 128 ms per loop

AICN


In [93]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AICN

algorithm_cls = AICN

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 582 ms per loop

AFC


In [77]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AFC

algorithm_cls = AFC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


10 loops, best of 3: 158 ms per loop

AFCN


In [78]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import AFCN

algorithm_cls = AFCN

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 563 ms per loop

ASC


In [95]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import ASC

algorithm_cls = ASC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 184 ms per loop

ABC


In [98]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import ABC

algorithm_cls = ABC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


1 loops, best of 3: 261 ms per loop

Bayesian Algorithms

BIC


In [59]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BIC

algorithm_cls = BIC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


10 loops, best of 3: 79.2 ms per loop

BICN


In [60]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BICN

algorithm_cls = BICN

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


10 loops, best of 3: 90.4 ms per loop

BFC


In [61]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BFC

algorithm_cls = BFC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


10 loops, best of 3: 139 ms per loop

BFCN


In [64]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BFCN

algorithm_cls = BFCN

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
<ipython-input-64-2c3e686a67c4> in <module>()
      8 s = fitter.perturb_shape(gt_s, noise_std=noise_std)
      9 
---> 10 get_ipython().magic(u'timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)')

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2203         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2204         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2205         return self.run_line_magic(magic_name, magic_arg_s)
   2206 
   2207     #-------------------------------------------------------------------------

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2124                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2125             with self.builtin_trap:
-> 2126                 result = fn(*args,**kwargs)
   2127             return result
   2128 

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in timeit(self, line, cell)

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in timeit(self, line, cell)
   1011             number = 1
   1012             for _ in range(1, 10):
-> 1013                 if timer.timeit(number) >= 0.2:
   1014                     break
   1015                 number *= 10

/data/installed/anaconda/envs/menpo/lib/python2.7/timeit.pyc in timeit(self, number)
    193         gc.disable()
    194         try:
--> 195             timing = self.inner(it, self.timer)
    196         finally:
    197             if gcold:

<magic-timeit> in inner(_it, _timer)

/data/pythondev/src/alabortijcv2015/alabortijcv2015/fitter.pyc in fit(self, image, initial_shape, max_iters, gt_shape, **kwargs)
    134         algorithm_results = self._fit(images, initial_shapes[0],
    135                                       max_iters=max_iters,
--> 136                                       gt_shapes=gt_shapes, **kwargs)
    137 
    138         # build multilevel fitting result

/data/pythondev/src/alabortijcv2015/alabortijcv2015/fitter.pyc in _fit(self, images, initial_shape, gt_shapes, max_iters, **kwargs)
    311 
    312             algorithm_result = alg.run(i, shape, gt_shape=gt_shape,
--> 313                                        max_iters=it, **kwargs)
    314             algorithm_results.append(algorithm_result)
    315 

/data/pythondev/src/alabortijcv2015/alabortijcv2015/aam/algorithm.pyc in run(self, image, initial_shape, gt_shape, max_iters, prior, l)
   2107 
   2108             # compute gauss-newton parameter updates
-> 2109             dp = self.interface.solve(h, j, e, prior)
   2110 
   2111             # update transform

/data/pythondev/src/alabortijcv2015/alabortijcv2015/aam/algorithm.pyc in solve(self, h, j, e, prior)
    259                                   t.j_prior * t.as_vector() - j.T.dot(e))
    260         else:
--> 261             dp = np.linalg.solve(h, j.T.dot(e))
    262 
    263         return dp

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/numpy/linalg/linalg.pyc in solve(a, b)
    379     signature = 'DD->D' if isComplexType(t) else 'dd->d'
    380     extobj = get_linalg_error_extobj(_raise_linalgerror_singular)
--> 381     r = gufunc(a, b, signature=signature, extobj=extobj)
    382 
    383     return wrap(r.astype(result_t))

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/numpy/linalg/linalg.pyc in _raise_linalgerror_singular(err, flag)
     88 
     89 def _raise_linalgerror_singular(err, flag):
---> 90     raise LinAlgError("Singular matrix")
     91 
     92 def _raise_linalgerror_nonposdef(err, flag):

LinAlgError: Singular matrix

BSC


In [99]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BSC

algorithm_cls = BSC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


10 loops, best of 3: 161 ms per loop

BBC


In [100]:
from alabortijcv2015.aam import PartsAAMFitter
from alabortijcv2015.aam.algorithm import BBC

algorithm_cls = BBC

if aam_type is ('GlobalAAM' or 'PatchAAM'):
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
    
elif aam_type is ('LinearGlobalAAM' or 'LinearPatchAAM'):
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                        n_appearance=n_appearance, sampling_mask=sampling_mask)

gt_s = i.landmarks[group].lms
s = fitter.perturb_shape(gt_s, noise_std=noise_std)

% timeit fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)


10 loops, best of 3: 200 ms per loop