In [1]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
repeat = 1

Load test data


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

path = '/data/'
group = 'lfpw_face'

test_images = []
for i in mio.import_images(path + 'PhD/DataBases/faces/cofw/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(1, group='PTS')
    
    if i.n_channels == 3:
        i = i.as_greyscale(mode='average')
    test_images.append(i)


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

In [4]:
from menpo.visualize import visualize_images

visualize_images(test_images)


Unified HDMs and HPDMs

Load Model


In [5]:
from alabortcvpr2015.utils import pickle_load

unified = pickle_load(path + 'PhD/Models/unified_cofw_fast_dsift')

AIC + RLMS


In [6]:
sampling_mask = np.require(np.zeros(unified.parts_shape), dtype=np.bool)
sampling_mask[3::7, 3::7] = True

imshow(sampling_mask)


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

In [ ]:
from alabortcvpr2015.unified import PartsUnifiedFitter, AICRLMS
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult

fitter = PartsUnifiedFitter(unified, algorithm_cls=AICRLMS, n_shape=[3, 12],
                            n_appearance=[25, 50], sampling_mask=sampling_mask)

fitter_results = []

for seed in xrange(repeat):

    np.random.seed(seed=seed)

    for j, i in enumerate(test_images[:100]):

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

        fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=False, a=0.9)

        fitter_results.append(fr)
        fr.downscale = 0.5

        print 'Image: ', j
        print fr

results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'AICRLMS', fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/unified_aicrlms_cofw_fast_dsift')


Image:  0
Initial error: 0.1455
Final error: 0.0618
Image:  1
Initial error: 0.1943
Final error: 0.0609
Image:  2
Initial error: 0.1043
Final error: 0.0289
Image:  3
Initial error: 0.0740
Final error: 0.0420
Image:  4
Initial error: 0.0568
Final error: 0.0369
Image:  5
Initial error: 0.0896
Final error: 0.0220
Image:  6
Initial error: 0.0515
Final error: 0.0276
Image:  7
Initial error: 0.0844
Final error: 0.0357
Image:  8
Initial error: 0.0743
Final error: 0.0363
Image:  9
Initial error: 0.0349
Final error: 0.0291
Image:  10
Initial error: 0.1329
Final error: 0.0373
Image:  11
Initial error: 0.0988
Final error: 0.0236
Image:  12
Initial error: 0.1064
Final error: 0.0462
Image:  13
Initial error: 0.0610
Final error: 0.0782
Image:  14
Initial error: 0.0597
Final error: 0.0353
Image:  15
Initial error: 0.1343
Final error: 0.0391
Image:  16
Initial error: 0.0953
Final error: 0.0242
Image:  17
Initial error: 0.0350
Final error: 0.0175
Image:  18
Initial error: 0.0438
Final error: 0.0428
Image:  19
Initial error: 0.0525
Final error: 0.0242
Image:  20
Initial error: 0.1728
Final error: 0.0867
Image:  21
Initial error: 0.0794
Final error: 0.0204
Image:  22
Initial error: 0.0570
Final error: 0.0267
Image:  23
Initial error: 0.0569
Final error: 0.0277
Image:  24
Initial error: 0.1400
Final error: 0.0219
Image:  25
Initial error: 0.0925
Final error: 0.0447
Image:  26
Initial error: 0.0780
Final error: 0.0355
Image:  27
Initial error: 0.1338
Final error: 0.0447
Image:  28
Initial error: 0.0598
Final error: 0.0245
Image:  29
Initial error: 0.0710
Final error: 0.0199
Image:  30
Initial error: 0.0756
Final error: 0.0393
Image:  31
Initial error: 0.0886
Final error: 0.0396
Image:  32
Initial error: 0.1199
Final error: 0.0283
Image:  33
Initial error: 0.0646
Final error: 0.0241
Image:  34
Initial error: 0.0666
Final error: 0.0310
Image:  35
Initial error: 0.0633
Final error: 0.0256
Image:  36
Initial error: 0.1225
Final error: 0.0393
Image:  37
Initial error: 0.1070
Final error: 0.0278
Image:  38
Initial error: 0.2081
Final error: 0.0444
Image:  39
Initial error: 0.1125
Final error: 0.0415
Image:  40
Initial error: 0.1040
Final error: 0.0266
Image:  41
Initial error: 0.1221
Final error: 0.0295
Image:  42
Initial error: 0.0702
Final error: 0.0231
Image:  43
Initial error: 0.0794
Final error: 0.0622
Image:  44
Initial error: 0.0574
Final error: 0.0253
Image:  45
Initial error: 0.1360
Final error: 0.0469
Image:  46
Initial error: 0.0614
Final error: 0.0321
Image:  47
Initial error: 0.1019
Final error: 0.0629
Image:  48
Initial error: 0.0547
Final error: 0.0497
Image:  49
Initial error: 0.1382
Final error: 0.0306
Image:  50
Initial error: 0.0935
Final error: 0.0386
Image:  51
Initial error: 0.0507
Final error: 0.0277
Image:  52
Initial error: 0.0813
Final error: 0.0565
Image:  53
Initial error: 0.0541
Final error: 0.0233
Image:  54
Initial error: 0.1199
Final error: 0.0375
Image:  55
Initial error: 0.0797
Final error: 0.0235
Image:  56
Initial error: 0.0550
Final error: 0.0581
Image:  57
Initial error: 0.2140
Final error: 0.2341
Image:  58
Initial error: 0.0827
Final error: 0.0250
Image:  59
Initial error: 0.2586
Final error: 0.2385
Image:  60
Initial error: 0.0609
Final error: 0.0464
Image:  61
Initial error: 0.0739
Final error: 0.0275
Image:  62
Initial error: 0.0645
Final error: 0.0374
Image:  63
Initial error: 0.1605
Final error: 0.0428
Image:  64
Initial error: 0.1035
Final error: 0.0225
Image:  65
Initial error: 0.1046
Final error: 0.0563
Image:  66
Initial error: 0.0749
Final error: 0.0419
Image:  67
Initial error: 0.1410
Final error: 0.0460
Image:  68
Initial error: 0.1158
Final error: 0.0504
Image:  69
Initial error: 0.1469
Final error: 0.0200
Image:  70
Initial error: 0.0782
Final error: 0.0224
Image:  71
Initial error: 0.0872
Final error: 0.0400
Image:  72
Initial error: 0.0511
Final error: 0.0363
Image:  73
Initial error: 0.0904
Final error: 0.0413
Image:  74
Initial error: 0.0529
Final error: 0.0264
Image:  75
Initial error: 0.0771
Final error: 0.0399
Image:  76
Initial error: 0.1009
Final error: 0.0219
Image:  77
Initial error: 0.0674
Final error: 0.0292
Image:  78
Initial error: 0.0708
Final error: 0.0361
Image:  79
Initial error: 0.0310
Final error: 0.0199
Image:  80
Initial error: 0.0736
Final error: 0.0432
Image:  81
Initial error: 0.1060
Final error: 0.0302
Image:  82
Initial error: 0.0856
Final error: 0.0456
Image:  83
Initial error: 0.1551
Final error: 0.0789
Image:  84
Initial error: 0.0984
Final error: 0.0311
Image:  85
Initial error: 0.0657
Final error: 0.0192
Image:  86
Initial error: 0.0528
Final error: 0.0240
Image:  87
Initial error: 0.0888
Final error: 0.0261
Image:  88
Initial error: 0.0645
Final error: 0.0353
Image:  89
Initial error: 0.0694
Final error: 0.0304
Image: 

Visualize Results


In [15]:
np.mean([fr.final_error(error_type='rmse') for fr in fitter_results])


Out[15]:
3.8146007390697689

In [9]:
from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)


PIC + RLMS


In [13]:
sampling_mask = np.require(np.zeros(unified.parts_shape), dtype=np.bool)
sampling_mask[3::7, 3::7] = True

imshow(sampling_mask)


Out[13]:
<matplotlib.image.AxesImage at 0x7f9d159f8b50>

In [14]:
from alabortcvpr2015.unified import PartsUnifiedFitter, PICRLMS
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult

fitter = PartsUnifiedFitter(unified, algorithm_cls=PICRLMS, n_shape=[3, 12],
                            n_appearance=[25, 50], sampling_mask=sampling_mask)

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
        s = fitter.perturb_shape(gt_s, noise_std=0.05)

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

        fitter_results.append(fr)
        fr.downscale = 0.5

        print 'Image: ', j
        print fr


results = [SerializableResult('none', fr.shapes(), fr.n_iters, 'PICRLMS', fr.gt_shape) 
           for fr in fitter_results]

pickle_dump(results, path + 'PhD/Results/unified_picrlms_cofw_fast_dsift')


Image:  0
Initial error: 0.1455
Final error: 0.0507
Image:  1
Initial error: 0.1943
Final error: 0.1657
Image:  2
Initial error: 0.1043
Final error: 0.0447
Image:  3
Initial error: 0.0740
Final error: 0.0403
Image:  4
Initial error: 0.0568
Final error: 0.0348
Image:  5
Initial error: 0.0896
Final error: 0.0578
Image:  6
Initial error: 0.0515
Final error: 0.0295
Image:  7
Initial error: 0.0844
Final error: 0.0560
Image:  8
Initial error: 0.0743
Final error: 0.0366
Image:  9
Initial error: 0.0349
Final error: 0.0276
Image:  10
Initial error: 0.1329
Final error: 0.0320
Image:  11
Initial error: 0.0988
Final error: 0.0412
Image:  12
Initial error: 0.1064
Final error: 0.0604
Image:  13
Initial error: 0.0610
Final error: 0.0664
Image:  14
Initial error: 0.0597
Final error: 0.0401
Image:  15
Initial error: 0.1343
Final error: 0.0396
Image:  16
Initial error: 0.0953
Final error: 0.0246
Image:  17
Initial error: 0.0350
Final error: 0.0190
Image:  18
Initial error: 0.0438
Final error: 0.0409
Image:  19
Initial error: 0.0525
Final error: 0.0259
Image:  20
Initial error: 0.1728
Final error: 0.1297
Image:  21
Initial error: 0.0794
Final error: 0.0176
Image:  22
Initial error: 0.0570
Final error: 0.0217
Image:  23
Initial error: 0.0569
Final error: 0.0348
Image:  24
Initial error: 0.1400
Final error: 0.0544
Image:  25
Initial error: 0.0925
Final error: 0.0472
Image:  26
Initial error: 0.0780
Final error: 0.0319
Image:  27
Initial error: 0.1338
Final error: 0.0471
Image:  28
Initial error: 0.0598
Final error: 0.0278
Image:  29
Initial error: 0.0710
Final error: 0.0175
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-14-17ea88284f50> in <module>()
     17         s = fitter.perturb_shape(gt_s, noise_std=0.05)
     18 
---> 19         fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=False)
     20 
     21         fitter_results.append(fr)

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

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

/data/pythondev/src/alabortcvpr2015/alabortcvpr2015/unified/algorithm.py in run(self, image, initial_shape, gt_shape, max_iters, prior)
    159             # get all (x, y) pairs being considered
    160             xys = (target.points[:, None, None, ...] +
--> 161                    self._sampling_grid)
    162 
    163             # build parts image

KeyboardInterrupt: 

Visualize Results


In [ ]:
np.mean([fr.final_error(error_type='rmse') for fr in fitter_results])

In [11]:
from menpofit.visualize import visualize_fitting_results

visualize_fitting_results(fitter_results)



In [ ]: