In [1]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
repeat = 3

Load test data


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

path = '/data/'
group = 'ibug_face_66'
db = 'lfpw'

test_images = []
for i in mio.import_images(path + 'PhD/DataBases/faces/' + db + '/testset', 
                           verbose=True, max_images=None):
    
    # 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 224 assets: [====================] 100%

In [4]:
from menpo.visualize import visualize_images

visualize_images(test_images)


Active Appearance Models


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

aam_type = 'GlobalAAM_PWA'
features_type = fast_dsift.__name__

aam = pickle_load(path + 'PhD/Models/ijcv2015/exp1_' + aam_type + '_' + features_type)

Fitting Parameters


In [6]:
sampling_step = 2

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

n_shape = [3, 12]
n_appearance = [250, 500]

noise_std = [0.04]
max_iters = 40
prior = False

imshow(sampling_mask)


Out[6]:
<matplotlib.image.AxesImage at 0x7f776c469710>

Simultaneous Algorithms

Simultaneous Inverse Compositional Newton (SICN)

from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter from alabortijcv2015.aam.algorithm import SICN

algorithm_cls = SICN

if isinstance(aam, PartsAAM): fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape, n_appearance=n_appearance, sampling_mask=sampling_mask) elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape, n_appearance=n_appearance, sampling_step=sampling_step) else: fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape, n_appearance=n_appearance, sampling_step=sampling_step)

from alabortijcv2015.utils import pickle_dump from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:

fitter_results = []

for seed in xrange(repeat):

    np.random.seed(seed=seed)

    for j, i in enumerate(test_images):

        gt_s = i.landmarks[group].lms

        if n is not None:
            s = fitter.perturb_shape(gt_s, noise_std=n)
        else:
            s = gt_s

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

        fitter_results.append(fr)
        fr.downscale = 0.5

        print 'Image: ', j
        print fr

    if n is (None or 0):
        break

print n

alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Simultaneous Forward Compositional Newton (SFCN)

from alabortijcv2015.aam import PartsAAMFitter from alabortijcv2015.aam.algorithm import SFCN

fitter = PartsAAMFitter(aam, algorithm_cls=SFCN, n_shape=n_shape, n_appearance=n_appearance, sampling_mask= sampling_mask)

from alabortijcv2015.utils import pickle_dump from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:

fitter_results = []

for seed in xrange(repeat):

    np.random.seed(seed=seed)

    for j, i in enumerate(test_images):

        gt_s = i.landmarks[group].lms

        if n is not None:
            s = fitter.perturb_shape(gt_s, noise_std=n)
        else:
            s = gt_s

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

        fitter_results.append(fr)
        fr.downscale = 0.5

        #print 'Image: ', j
        #print fr

    if n is (None or 0):
        break

print n

alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Simultaneous Symmetric Compositional (SSC)


In [11]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import SIC2

algorithm_cls = SIC2

if isinstance(aam, PartsAAM):
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                            n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): 
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)

In [12]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:
    
    fitter_results = []
    
    for seed in xrange(repeat):

        np.random.seed(seed=seed)

        for j, i in enumerate(test_images):

            gt_s = i.landmarks[group].lms

            if n is not None:
                s = fitter.perturb_shape(gt_s, noise_std=n)
            else:
                s = gt_s

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

            fitter_results.append(fr)
            fr.downscale = 0.5

            print 'Image: ', j
            print fr
        
        if n is (None or 0):
            break
    
    print n

    alg_type = fitter._algorithms[0].__class__.__name__
    results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
               for fr in fitter_results]

    pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))


Image:  0
Initial error: 0.1195
Final error: 0.0248
Image:  1
Initial error: 0.0785
Final error: 0.0186
Image:  2
Initial error: 0.0555
Final error: 0.0642
Image:  3
Initial error: 0.0415
Final error: 0.0218
Image:  4
Initial error: 0.0662
Final error: 0.0263
Image:  5
Initial error: 0.0759
Final error: 0.0301
Image:  6
Initial error: 0.0548
Final error: 0.0224
Image:  7
Initial error: 0.0881
Final error: 0.0541
Image:  8
Initial error: 0.0736
Final error: 0.0292
Image:  9
Initial error: 0.0293
Final error: 0.0196
Image:  10
Initial error: 0.1174
Final error: 0.1571
Image:  11
Initial error: 0.0775
Final error: 0.0260
Image:  12
Initial error: 0.0761
Final error: 0.0205
Image:  13
Initial error: 0.0394
Final error: 0.0196
Image:  14
Initial error: 0.0917
Final error: 0.0285
Image:  15
Initial error: 0.1001
Final error: 0.0278
Image:  16
Initial error: 0.0817
Final error: 0.0168
Image:  17
Initial error: 0.0941
Final error: 0.0253
Image:  18
Initial error: 0.0595
Final error: 0.0359
Image:  19
Initial error: 0.0478
Final error: 0.0371
Image:  20
Initial error: 0.1036
Final error: 0.0218
Image:  21
Initial error: 0.0851
Final error: 0.0280
Image:  22
Initial error: 0.0755
Final error: 0.0200
Image:  23
Initial error: 0.0375
Final error: 0.0401
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-12-fd8a96d87a89> in <module>()
     19                 s = gt_s
     20 
---> 21             fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
     22 
     23             fitter_results.append(fr)

/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.py in run(self, image, initial_shape, gt_shape, max_iters, prior)
    988 
    989             # save cost
--> 990             cost.append(e.T.dot(self.project_out(e[..., None])[..., 0]))
    991 
    992         # return aam algorithm result

/data/pythondev/src/alabortijcv2015/alabortijcv2015/aam/algorithm.py in project_out(self, j)
    344 
    345     def project_out(self, j):
--> 346         return j - self._masked_U.dot(self._pinv_U.T.dot(j))
    347 
    348 

KeyboardInterrupt: 

In [10]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:
    
    fitter_results = []
    
    for seed in xrange(repeat):

        np.random.seed(seed=seed)

        for j, i in enumerate(test_images):

            gt_s = i.landmarks[group].lms

            if n is not None:
                s = fitter.perturb_shape(gt_s, noise_std=n)
            else:
                s = gt_s

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

            fitter_results.append(fr)
            fr.downscale = 0.5

            print 'Image: ', j
            print fr
        
        if n is (None or 0):
            break
    
    print n

    alg_type = fitter._algorithms[0].__class__.__name__
    results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
               for fr in fitter_results]

    pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))


Image:  0
Initial error: 0.1195
Final error: 0.0180
Image:  1
Initial error: 0.0785
Final error: 0.0167
Image:  2
Initial error: 0.0555
Final error: 0.0605
Image:  3
Initial error: 0.0415
Final error: 0.0216
Image:  4
Initial error: 0.0662
Final error: 0.0271
Image:  5
Initial error: 0.0759
Final error: 0.0303
Image:  6
Initial error: 0.0548
Final error: 0.0221
Image:  7
Initial error: 0.0881
Final error: 0.0665
Image:  8
Initial error: 0.0736
Final error: 0.0318
Image:  9
Initial error: 0.0293
Final error: 0.0192
Image:  10
Initial error: 0.1174
Final error: 0.1581
Image:  11
Initial error: 0.0775
Final error: 0.0265
Image:  12
Initial error: 0.0761
Final error: 0.0183
Image:  13
Initial error: 0.0394
Final error: 0.0233
Image:  14
Initial error: 0.0917
Final error: 0.0290
Image:  15
Initial error: 0.1001
Final error: 0.0211
Image:  16
Initial error: 0.0817
Final error: 0.0205
Image:  17
Initial error: 0.0941
Final error: 0.0252
Image:  18
Initial error: 0.0595
Final error: 0.0364
Image:  19
Initial error: 0.0478
Final error: 0.0372
Image:  20
Initial error: 0.1036
Final error: 0.0195
Image:  21
Initial error: 0.0851
Final error: 0.0291
Image:  22
Initial error: 0.0755
Final error: 0.0196
Image:  23
Initial error: 0.0375
Final error: 0.0365
Image:  24
Initial error: 0.0575
Final error: 0.0537
Image:  25
Initial error: 0.0848
Final error: 0.0256
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-10-fd8a96d87a89> in <module>()
     19                 s = gt_s
     20 
---> 21             fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=max_iters, prior=prior)
     22 
     23             fitter_results.append(fr)

/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.py in run(self, image, initial_shape, gt_shape, max_iters, prior)
    425 
    426             # compute warped image with current weights
--> 427             i = self.interface.warp(image)
    428 
    429             # reconstruct appearance

/data/pythondev/src/alabortijcv2015/alabortijcv2015/aam/algorithm.py in warp(self, image)
     82     def warp(self, image):
     83         return image.warp_to_mask(self.algorithm.template.mask,
---> 84                                   self.algorithm.transform)
     85 
     86     def gradient(self, image):

/data/pythondev/src/menpofast/menpofast/image/base.pyc in warp_to_mask(self, template_mask, transform, warp_landmarks, order, mode, cval)
    931         # sampled pixels. Store those in a (n_pixels, n_channels) array.
    932         sampled_pixel_values = scipy_interpolation(
--> 933             self.pixels, points_to_sample, order=order, mode=mode, cval=cval)
    934         # set any nan values to 0
    935         sampled_pixel_values[np.isnan(sampled_pixel_values)] = 0

/data/pythondev/src/menpofast/menpofast/image/interpolation.pyc in scipy_interpolation(pixels, points_to_sample, mode, order, cval)
     54                                                     mode=mode,
     55                                                     order=order,
---> 56                                                     cval=cval))
     57     sampled_pixel_values = [v.reshape([1, -1]) for v in sampled_pixel_values]
     58     return np.concatenate(sampled_pixel_values, axis=0)

/data/installed/anaconda/envs/menpo/lib/python2.7/site-packages/scipy/ndimage/interpolation.pyc in map_coordinates(input, coordinates, output, order, mode, cval, prefilter)
    306                                                    shape=output_shape)
    307     _nd_image.geometric_transform(filtered, None, coordinates, None, None,
--> 308                output, order, mode, cval, None, None)
    309     return return_value
    310 

KeyboardInterrupt: 

In [10]:
from menpofit.visualize import visualize_fitting_results
    
visualize_fitting_results(fitter_results)


Simultaneous Bidirectional Algorithm (SBC)


In [ ]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import SBC

algorithm_cls = SBC

if isinstance(aam, PartsAAM):
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                            n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): 
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)

In [ ]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
    
for n in noise_std:
    
    fitter_results = []
    
    for seed in xrange(repeat):

        np.random.seed(seed=seed)

        for j, i in enumerate(test_images):

            gt_s = i.landmarks[group].lms

            if n is not None:
                s = fitter.perturb_shape(gt_s, noise_std=n)
            else:
                s = gt_s

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

            fitter_results.append(fr)
            fr.downscale = 0.5

            #print 'Image: ', j
            #print fr
            
        if n is (None or 0):
            break
            
    print n

    alg_type = fitter._algorithms[0].__class__.__name__
    results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
               for fr in fitter_results]
    
    pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Alternating Algorithms

Alternating Inverse Compositional Newton (AICN)

from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter from alabortijcv2015.aam.algorithm import AICN

algorithm_cls = AICN

if isinstance(aam, PartsAAM): fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape, n_appearance=n_appearance, sampling_mask=sampling_mask) elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape, n_appearance=n_appearance, sampling_step=sampling_step) else: fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape, n_appearance=n_appearance, sampling_step=sampling_step)

from alabortijcv2015.utils import pickle_dump from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:

fitter_results = []

for seed in xrange(repeat):

    np.random.seed(seed=seed)

    for j, i in enumerate(test_images):

        gt_s = i.landmarks[group].lms

        if n is not None:
            s = fitter.perturb_shape(gt_s, noise_std=n)
        else:
            s = gt_s

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

        fitter_results.append(fr)
        fr.downscale = 0.5

        print 'Image: ', j
        print fr

    if n is (None or 0):
        break

print n

alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Alternating Forward Compositional Newton (AFCN)

from alabortijcv2015.aam import PartsAAMFitter from alabortijcv2015.aam.algorithm import AFCN

fitter = PartsAAMFitter(aam, algorithm_cls=AFCN, n_shape=n_shape, n_appearance=n_appearance, sampling_mask=sampling_mask)

from alabortijcv2015.utils import pickle_dump from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:

fitter_results = []

for seed in xrange(repeat):

    np.random.seed(seed=seed)

    for j, i in enumerate(test_images):

        gt_s = i.landmarks[group].lms

        if n is not None:
            s = fitter.perturb_shape(gt_s, noise_std=n)
        else:
            s = gt_s

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

        fitter_results.append(fr)
        fr.downscale = 0.5

        #print 'Image: ', j
        #print fr

    if n is (None or 0):
        break

print n

alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Alternating Symmetric Compositional (ASC)


In [11]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import ASC

algorithm_cls = ASC

if isinstance(aam, PartsAAM):
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                            n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): 
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)

In [12]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
    
for n in noise_std:
    
    fitter_results = []
    
    for seed in xrange(repeat):

        np.random.seed(seed=seed)

        for j, i in enumerate(test_images):

            gt_s = i.landmarks[group].lms

            if n is not None:
                s = fitter.perturb_shape(gt_s, noise_std=n)
            else:
                s = gt_s

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

            fitter_results.append(fr)
            fr.downscale = 0.5

            #print 'Image: ', j
            #print fr
        
        if n is (None or 0):
            break
            
    print n

    alg_type = fitter._algorithms[0].__class__.__name__
    results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
               for fr in fitter_results]

    pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))


0.04

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Alternating Bidirectional Compositional (ABC)


In [13]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import ABC

algorithm_cls = ABC

if isinstance(aam, PartsAAM):
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                            n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): 
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)

In [14]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
    
for n in noise_std:
    
    fitter_results = []
    
    for seed in xrange(repeat):

        np.random.seed(seed=seed)

        for j, i in enumerate(test_images):

            gt_s = i.landmarks[group].lms

            if n is not None:
                s = fitter.perturb_shape(gt_s, noise_std=n)
            else:
                s = gt_s

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

            fitter_results.append(fr)
            fr.downscale = 0.5

            #print 'Image: ', j
            #print fr
        
        if n is (None or 0):
            break
            
    print n

    alg_type = fitter._algorithms[0].__class__.__name__
    results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
               for fr in fitter_results]

    pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))


0.04

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Bayesian Algorithms

Bayesian Inverse Compositional Newton (BICN)

from alabortijcv2015.aam import PartsAAMFitter from alabortijcv2015.aam.algorithm import BICN

fitter = PartsAAMFitter(aam, algorithm_cls=BICN, n_shape=n_shape, n_appearance=n_appearance, sampling_mask=sampling_mask)

from alabortijcv2015.utils import pickle_dump from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:

fitter_results = []

for seed in xrange(repeat):

    np.random.seed(seed=seed)

    for j, i in enumerate(test_images):

        gt_s = i.landmarks[group].lms

        if n is not None:
            s = fitter.perturb_shape(gt_s, noise_std=n)
        else:
            s = gt_s

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

        fitter_results.append(fr)
        fr.downscale = 0.5

        #print 'Image: ', j
        #print fr

    if n is (None or 0):
        break

print n

alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Bayesian Forward Compositional Newton (BFCN)

from alabortijcv2015.aam import PartsAAMFitter from alabortijcv2015.aam.algorithm import BFCN

fitter = PartsAAMFitter(aam, algorithm_cls=BFCN, n_shape=n_shape, n_appearance=n_appearance, sampling_mask=sampling_mask)

from alabortijcv2015.utils import pickle_dump from alabortijcv2015.aam import SerializableAAMFitterResult

for n in noise_std:

fitter_results = []

for seed in xrange(repeat):

    np.random.seed(seed=seed)

    for j, i in enumerate(test_images):

        gt_s = i.landmarks[group].lms

        if n is not None:
            s = fitter.perturb_shape(gt_s, noise_std=n)
        else:
            s = gt_s

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

        fitter_results.append(fr)
        fr.downscale = 0.5

        #print 'Image: ', j
        #print fr

    if n is (None or 0):
        break

print n

alg_type = fitter._algorithms[0].__class__.__name__
results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Bayesian Symmetric Compositional (BSC)


In [15]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import BSC

algorithm_cls = BSC

if isinstance(aam, PartsAAM):
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                            n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): 
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)

In [16]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
    
for n in noise_std:
    
    fitter_results = []
    
    for seed in xrange(repeat):

        np.random.seed(seed=seed)

        for j, i in enumerate(test_images):

            gt_s = i.landmarks[group].lms

            if n is not None:
                s = fitter.perturb_shape(gt_s, noise_std=n)
            else:
                s = gt_s

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

            fitter_results.append(fr)
            fr.downscale = 0.5

            #print 'Image: ', j
            #print fr
        
        if n is (None or 0):
            break
            
    print n

    alg_type = fitter._algorithms[0].__class__.__name__
    results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
               for fr in fitter_results]

    pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))


0.04

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)

Bayesian Bidirectional Compositional (BBC)


In [17]:
from alabortijcv2015.aam import GlobalAAM, PatchAAM, LinearGlobalAAM, LinearPatchAAM, PartsAAM
from alabortijcv2015.aam import StandardAAMFitter, LinearAAMFitter, PartsAAMFitter
from alabortijcv2015.aam.algorithm import BBC

algorithm_cls = BBC

if isinstance(aam, PartsAAM):
    fitter = PartsAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                            n_appearance=n_appearance, sampling_mask=sampling_mask)
elif isinstance(aam, GlobalAAM) or isinstance(aam, PatchAAM): 
    fitter = StandardAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                               n_appearance=n_appearance, sampling_step=sampling_step)
else:
    fitter = LinearAAMFitter(aam, algorithm_cls=algorithm_cls, n_shape=n_shape,
                             n_appearance=n_appearance, sampling_step=sampling_step)

In [18]:
from alabortijcv2015.utils import pickle_dump
from alabortijcv2015.aam import SerializableAAMFitterResult
    
for n in noise_std:
    
    fitter_results = []
    
    for seed in xrange(repeat):

        np.random.seed(seed=seed)

        for j, i in enumerate(test_images):

            gt_s = i.landmarks[group].lms

            if n is not None:
                s = fitter.perturb_shape(gt_s, noise_std=n)
            else:
                s = gt_s

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

            fitter_results.append(fr)
            fr.downscale = 0.5

            #print 'Image: ', j
            #print fr
            
        if n is (None or 0):
            break
            
    print n

    alg_type = fitter._algorithms[0].__class__.__name__
    results = [SerializableAAMFitterResult('none', fr.shapes(), fr.costs(), fr.n_iters, alg_type, fr.gt_shape) 
               for fr in fitter_results]

    pickle_dump(results, path + 'PhD/Results/ijcv2015/exp3_' + aam_type + '_' + features_type + '_' + alg_type + '_' + db + '_' + str(n))


0.04

from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)