In [1]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib

Load training data


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

training_images = []
for i in mio.import_images('/data/PhD/DataBases/faces/lfpw/trainset/', verbose=True, 
                           max_images=None):
    
    # convert the image from menpo Image to menpofast Image (channels at front)
    i = convert_from_menpo(i)
    
    i.rescale_landmarks_to_diagonal_range(200)
    i.crop_to_landmarks_proportion_inplace(0.5)
    labeller(i, 'PTS', ibug_face_66)
    if i.n_channels == 3:
        i = i.as_greyscale(mode='average')
    training_images.append(i)


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

In [4]:
from menpo.visualize import visualize_images

visualize_images(training_images)


Load test data


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

test_images = []
for i in mio.import_images('/data/PhD/DataBases/faces/afw/', verbose=True, 
                           max_images=None):
    
    # convert the image from menpo Image to menpofast Image (channels at front)
    i = convert_from_menpo(i)
    
    i.crop_to_landmarks_proportion_inplace(0.5)
    labeller(i, 'PTS', ibug_face_66)
    if i.n_channels == 3:
        i = i.as_greyscale(mode='average')
    test_images.append(i)


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

In [15]:
from menpo.visualize import visualize_images

visualize_images(test_images)


Active Appearance Models

Global Warp

Build


In [ ]:
from menpofast.feature import no_op, aam_dsift
from alabortcvpr2015.aam import GlobalAAMBuilder

builder = GlobalAAMBuilder(features=aam_dsift, diagonal=100, 
                           scale_shapes=False, scales=(1, .5))
aam = builder.build(training_images, group='ibug_face_66', verbose=True)

Test


In [ ]:
from alabortcvpr2015.aam import GlobalAAMFitter, AIC, PIC
                  
fitter = GlobalAAMFitter(aam, algorithm_cls=AIC, n_shape=[3, 12], 
                         n_appearance=[25, 50], sampling_step=8)

In [ ]:
np.random.seed(seed=1)

fitter_results = []

for j, i in enumerate(test_images[:]):
    
    gt_s = i.landmarks['ibug_face_66'].lms
    s = fitter.perturb_shape(gt_s, noise_std=0.05)
    
    fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=True)
    fr.downscale = 0.5
    
    fitter_results.append(fr)
    
    print 'Image: ', j
    print fr

Visualize Results


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

Timing

Total


In [ ]:
%timeit fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Per line


In [ ]:
import line_profiler
import IPython

ip = IPython.get_ipython()
ip.define_magic('lprun', line_profiler.magic_lprun)

In [ ]:
from alabortcvpr2015.aam import AIC

%lprun -f AIC.run fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Local Warp

Build


In [7]:
from menpofast.feature import no_op, fast_dsift
from alabortcvpr2015.aam import PartsAAMBuilder

builder = PartsAAMBuilder(parts_shape=(15, 15), features=fast_dsift, diagonal=100, 
                          scale_shapes=False, scales=(1, .5))
aam = builder.build(training_images, group='ibug_face_66', verbose=True)


- Building models
  - Level 0: Done
  - Level 1: Done

Test


In [8]:
sampling_mask = np.require(np.zeros(aam.parts_shape), dtype=np.bool)
sampling_mask[:] = True

imshow(sampling_mask)


Out[8]:
<matplotlib.image.AxesImage at 0x7f1248066550>

In [9]:
from alabortcvpr2015.aam import PartsAAMFitter, AIC, PIC
                  
fitter = PartsAAMFitter(aam, algorithm_cls=PIC, n_shape=[3, 12], 
                        n_appearance=None, sampling_mask=sampling_mask)

In [16]:
np.random.seed(seed=1)

fitter_results = []

for j, i in enumerate(test_images[:]):
    
    gt_s = i.landmarks['ibug_face_66'].lms
    s = fitter.perturb_shape(gt_s, noise_std=0.04)
    
    fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=50, prior=True)
    fr.downscale = 0.5
    
    fitter_results.append(fr)
    
    print 'Image: ', j
    print fr


Image:  0
Initial error: 0.0357
Final error: 0.0135
Image:  1
Initial error: 0.1015
Final error: 0.0263
Image:  2
Initial error: 0.1458
Final error: 0.0574
Image:  3
Initial error: 0.1066
Final error: 0.1183
Image:  4
Initial error: 0.0712
Final error: 0.0243
Image:  5
Initial error: 0.0663
Final error: 0.0141
Image:  6
Initial error: 0.0639
Final error: 0.0287
Image:  7
Initial error: 0.0609
Final error: 0.0630
Image:  8
Initial error: 0.0847
Final error: 0.0238
Image:  9
Initial error: 0.0728
Final error: 0.0317
Image:  10
Initial error: 0.0994
Final error: 0.0340
Image:  11
Initial error: 0.1256
Final error: 0.0720
Image:  12
Initial error: 0.1183
Final error: 0.0341
Image:  13
Initial error: 0.1118
Final error: 0.0438
Image:  14
Initial error: 0.0844
Final error: 0.0817
Image:  15
Initial error: 0.1114
Final error: 0.0723
Image:  16
Initial error: 0.1017
Final error: 0.0535
Image:  17
Initial error: 0.0611
Final error: 0.0588
Image:  18
Initial error: 0.1002
Final error: 0.0725
Image:  19
Initial error: 0.0746
Final error: 0.0239
Image:  20
Initial error: 0.0590
Final error: 0.0279
Image:  21
Initial error: 0.0880
Final error: 0.0215
Image:  22
Initial error: 0.1016
Final error: 0.0736
Image:  23
Initial error: 0.0607
Final error: 0.0799
Image:  24
Initial error: 0.0776
Final error: 0.0343
Image:  25
Initial error: 0.1159
Final error: 0.1648
Image:  26
Initial error: 0.1008
Final error: 0.0218
Image:  27
Initial error: 0.1150
Final error: 0.0382
Image:  28
Initial error: 0.0898
Final error: 0.0262
Image:  29
Initial error: 0.1275
Final error: 0.0793
Image:  30
Initial error: 0.1301
Final error: 0.0419
Image:  31
Initial error: 0.0973
Final error: 0.0342
Image:  32
Initial error: 0.1191
Final error: 0.0579
Image:  33
Initial error: 0.1241
Final error: 0.0873
Image:  34
Initial error: 0.0985
Final error: 0.0453
Image:  35
Initial error: 0.0916
Final error: 0.0416
Image:  36
Initial error: 0.0832
Final error: 0.0596
Image:  37
Initial error: 0.1077
Final error: 0.0229
Image:  38
Initial error: 0.0937
Final error: 0.0357
Image:  39
Initial error: 0.1004
Final error: 0.0537
Image:  40
Initial error: 0.0572
Final error: 0.0198
Image:  41
Initial error: 0.0645
Final error: 0.0166
Image:  42
Initial error: 0.0804
Final error: 0.0200
Image:  43
Initial error: 0.0558
Final error: 0.0208
Image:  44
Initial error: 0.0913
Final error: 0.0201
Image:  45
Initial error: 0.1097
Final error: 0.0242
Image:  46
Initial error: 0.0795
Final error: 0.0382
Image:  47
Initial error: 0.0989
Final error: 0.0284
Image:  48
Initial error: 0.0785
Final error: 0.0295
Image:  49
Initial error: 0.0882
Final error: 0.0450
Image:  50
Initial error: 0.1051
Final error: 0.0954
Image:  51
Initial error: 0.1362
Final error: 0.1204
Image:  52
Initial error: 0.1092
Final error: 0.0418
Image:  53
Initial error: 0.0916
Final error: 0.0220
Image:  54
Initial error: 0.0803
Final error: 0.0210
Image:  55
Initial error: 0.1383
Final error: 0.0652
Image:  56
Initial error: 0.0956
Final error: 0.0221
Image:  57
Initial error: 0.0846
Final error: 0.0354
Image:  58
Initial error: 0.0753
Final error: 0.0399
Image:  59
Initial error: 0.1394
Final error: 0.0290
Image:  60
Initial error: 0.0922
Final error: 0.0748
Image:  61
Initial error: 0.0729
Final error: 0.0195
Image:  62
Initial error: 0.0501
Final error: 0.0175
Image:  63
Initial error: 0.1392
Final error: 0.0301
Image:  64
Initial error: 0.0740
Final error: 0.0141
Image:  65
Initial error: 0.0656
Final error: 0.0317
Image:  66
Initial error: 0.0731
Final error: 0.0265
Image:  67
Initial error: 0.1025
Final error: 0.0314
Image:  68
Initial error: 0.0472
Final error: 0.0167
Image:  69
Initial error: 0.1213
Final error: 0.0281
Image:  70
Initial error: 0.0986
Final error: 0.0790
Image:  71
Initial error: 0.0517
Final error: 0.0186
Image:  72
Initial error: 0.0845
Final error: 0.0212
Image:  73
Initial error: 0.0533
Final error: 0.0287
Image:  74
Initial error: 0.0927
Final error: 0.0518
Image:  75
Initial error: 0.0464
Final error: 0.0298
Image:  76
Initial error: 0.0616
Final error: 0.0386
Image:  77
Initial error: 0.0984
Final error: 0.1564
Image:  78
Initial error: 0.1709
Final error: 0.1934
Image:  79
Initial error: 0.0730
Final error: 0.0446
Image:  80
Initial error: 0.0733
Final error: 0.0377
Image:  81
Initial error: 0.0848
Final error: 0.0229
Image:  82
Initial error: 0.0789
Final error: 0.0678
Image:  83
Initial error: 0.0800
Final error: 0.0312
Image:  84
Initial error: 0.1955
Final error: 0.0369
Image:  85
Initial error: 0.0899
Final error: 0.0373
Image:  86
Initial error: 0.0639
Final error: 0.0510
Image:  87
Initial error: 0.0737
Final error: 0.0513
Image:  88
Initial error: 0.0751
Final error: 0.0408
Image:  89
Initial error: 0.0804
Final error: 0.0498
Image:  90
Initial error: 0.1315
Final error: 0.0423
Image:  91
Initial error: 0.1426
Final error: 0.0482
Image:  92
Initial error: 0.0302
Final error: 0.0148
Image:  93
Initial error: 0.0968
Final error: 0.0141
Image:  94
Initial error: 0.1216
Final error: 0.0171
Image:  95
Initial error: 0.0603
Final error: 0.0248
Image:  96
Initial error: 0.0275
Final error: 0.0220
Image:  97
Initial error: 0.1116
Final error: 0.0414
Image:  98
Initial error: 0.1117
Final error: 0.0296
Image:  99
Initial error: 0.1018
Final error: 0.0925
Image:  100
Initial error: 0.0890
Final error: 0.0338
Image:  101
Initial error: 0.1499
Final error: 0.0281
Image:  102
Initial error: 0.0918
Final error: 0.0365
Image:  103
Initial error: 0.1238
Final error: 0.0371
Image:  104
Initial error: 0.1406
Final error: 0.0398
Image:  105
Initial error: 0.0940
Final error: 0.0302
Image:  106
Initial error: 0.1061
Final error: 0.0792
Image:  107
Initial error: 0.0773
Final error: 0.0218
Image:  108
Initial error: 0.0676
Final error: 0.0211
Image:  109
Initial error: 0.0919
Final error: 0.0196
Image:  110
Initial error: 0.0786
Final error: 0.0205
Image:  111
Initial error: 0.1299
Final error: 0.1634
Image:  112
Initial error: 0.0597
Final error: 0.0403
Image:  113
Initial error: 0.0857
Final error: 0.0325
Image:  114
Initial error: 0.0606
Final error: 0.0319
Image:  115
Initial error: 0.0753
Final error: 0.0389
Image:  116
Initial error: 0.1330
Final error: 0.0531
Image:  117
Initial error: 0.0658
Final error: 0.0561
Image:  118
Initial error: 0.0904
Final error: 0.0420
Image:  119
Initial error: 0.1017
Final error: 0.0587
Image:  120
Initial error: 0.1662
Final error: 0.0488
Image:  121
Initial error: 0.1317
Final error: 0.0190
Image:  122
Initial error: 0.0671
Final error: 0.0365
Image:  123
Initial error: 0.1005
Final error: 0.0193
Image:  124
Initial error: 0.0914
Final error: 0.0350
Image:  125
Initial error: 0.1259
Final error: 0.0538
Image:  126
Initial error: 0.0964
Final error: 0.0959
Image:  127
Initial error: 0.0916
Final error: 0.0249
Image:  128
Initial error: 0.0873
Final error: 0.0382
Image:  129
Initial error: 0.0427
Final error: 0.0223
Image:  130
Initial error: 0.1280
Final error: 0.1621
Image:  131
Initial error: 0.1016
Final error: 0.0505
Image:  132
Initial error: 0.0842
Final error: 0.0295
Image:  133
Initial error: 0.0554
Final error: 0.0302
Image:  134
Initial error: 0.0801
Final error: 0.0505
Image:  135
Initial error: 0.0895
Final error: 0.0483
Image:  136
Initial error: 0.1039
Final error: 0.0261
Image:  137
Initial error: 0.0598
Final error: 0.0257
Image:  138
Initial error: 0.0824
Final error: 0.0199
Image:  139
Initial error: 0.0756
Final error: 0.0356
Image:  140
Initial error: 0.1338
Final error: 0.0863
Image:  141
Initial error: 0.1066
Final error: 0.0568
Image:  142
Initial error: 0.0706
Final error: 0.0275
Image:  143
Initial error: 0.0683
Final error: 0.0754
Image:  144
Initial error: 0.1049
Final error: 0.0246
Image:  145
Initial error: 0.1223
Final error: 0.0910
Image:  146
Initial error: 0.1274
Final error: 0.0554
Image:  147
Initial error: 0.0652
Final error: 0.0503
Image:  148
Initial error: 0.1363
Final error: 0.1330
Image:  149
Initial error: 0.1178
Final error: 0.0448
Image:  150
Initial error: 0.1042
Final error: 0.0217
Image:  151
Initial error: 0.0959
Final error: 0.0389
Image:  152
Initial error: 0.0654
Final error: 0.0179
Image:  153
Initial error: 0.0975
Final error: 0.0334
Image:  154
Initial error: 0.0860
Final error: 0.0215
Image:  155
Initial error: 0.0790
Final error: 0.0183
Image:  156
Initial error: 0.0649
Final error: 0.0370
Image:  157
Initial error: 0.0659
Final error: 0.0255
Image:  158
Initial error: 0.0450
Final error: 0.0229
Image:  159
Initial error: 0.0932
Final error: 0.0738
Image:  160
Initial error: 0.0824
Final error: 0.0425
Image:  161
Initial error: 0.1517
Final error: 0.1058
Image:  162
Initial error: 0.1031
Final error: 0.0354
Image:  163
Initial error: 0.1095
Final error: 0.0316
Image:  164
Initial error: 0.0969
Final error: 0.0516
Image:  165
Initial error: 0.0861
Final error: 0.0350
Image:  166
Initial error: 0.0877
Final error: 0.0199
Image:  167
Initial error: 0.1248
Final error: 0.0269
Image:  168
Initial error: 0.1353
Final error: 0.0429
Image:  169
Initial error: 0.1078
Final error: 0.0370
Image:  170
Initial error: 0.1265
Final error: 0.0229
Image:  171
Initial error: 0.1137
Final error: 0.0967
Image:  172
Initial error: 0.0513
Final error: 0.0237
Image:  173
Initial error: 0.0633
Final error: 0.0442
Image:  174
Initial error: 0.0473
Final error: 0.0323
Image:  175
Initial error: 0.0824
Final error: 0.0401
Image:  176
Initial error: 0.0927
Final error: 0.0744
Image:  177
Initial error: 0.1155
Final error: 0.0500
Image:  178
Initial error: 0.0886
Final error: 0.0548
Image:  179
Initial error: 0.0881
Final error: 0.2772
Image:  180
Initial error: 0.0885
Final error: 0.0505
Image:  181
Initial error: 0.1195
Final error: 0.0895
Image:  182
Initial error: 0.0485
Final error: 0.0169
Image:  183
Initial error: 0.1032
Final error: 0.0451
Image:  184
Initial error: 0.1308
Final error: 0.0486
Image:  185
Initial error: 0.0788
Final error: 0.0230
Image:  186
Initial error: 0.0506
Final error: 0.0168
Image:  187
Initial error: 0.0676
Final error: 0.0193
Image:  188
Initial error: 0.0411
Final error: 0.0181
Image:  189
Initial error: 0.0613
Final error: 0.0205
Image:  190
Initial error: 0.1037
Final error: 0.0226
Image:  191
Initial error: 0.0548
Final error: 0.0287
Image:  192
Initial error: 0.0977
Final error: 0.0269
Image:  193
Initial error: 0.1023
Final error: 0.0248
Image:  194
Initial error: 0.1107
Final error: 0.0312
Image:  195
Initial error: 0.0746
Final error: 0.0556
Image:  196
Initial error: 0.0409
Final error: 0.0339
Image:  197
Initial error: 0.1167
Final error: 0.0357
Image:  198
Initial error: 0.1110
Final error: 0.0328
Image:  199
Initial error: 0.0910
Final error: 0.0213
Image:  200
Initial error: 0.0961
Final error: 0.0161
Image:  201
Initial error: 0.0962
Final error: 0.0319
Image:  202
Initial error: 0.1001
Final error: 0.0728
Image:  203
Initial error: 0.1675
Final error: 0.2155
Image:  204
Initial error: 0.0685
Final error: 0.0435
Image:  205
Initial error: 0.0514
Final error: 0.0309
Image:  206
Initial error: 0.0385
Final error: 0.0178
Image:  207
Initial error: 0.0892
Final error: 0.0257
Image:  208
Initial error: 0.0808
Final error: 0.0238
Image:  209
Initial error: 0.0346
Final error: 0.0229
Image:  210
Initial error: 0.0995
Final error: 0.0328
Image:  211
Initial error: 0.0666
Final error: 0.0370
Image:  212
Initial error: 0.0851
Final error: 0.1232
Image:  213
Initial error: 0.1211
Final error: 0.0871
Image:  214
Initial error: 0.0565
Final error: 0.0253
Image:  215
Initial error: 0.1055
Final error: 0.0574
Image:  216
Initial error: 0.1015
Final error: 0.0236
Image:  217
Initial error: 0.0959
Final error: 0.0210
Image:  218
Initial error: 0.0786
Final error: 0.0191
Image:  219
Initial error: 0.0820
Final error: 0.0370
Image:  220
Initial error: 0.1155
Final error: 0.1126
Image:  221
Initial error: 0.0785
Final error: 0.0284
Image:  222
Initial error: 0.0597
Final error: 0.0244
Image:  223
Initial error: 0.1830
Final error: 0.0573
Image:  224
Initial error: 0.1221
Final error: 0.0242
Image:  225
Initial error: 0.1964
Final error: 0.0765
Image:  226
Initial error: 0.0918
Final error: 0.0340
Image:  227
Initial error: 0.1097
Final error: 0.0232
Image:  228
Initial error: 0.0599
Final error: 0.0345
Image:  229
Initial error: 0.0916
Final error: 0.0240
Image:  230
Initial error: 0.1100
Final error: 0.1727
Image:  231
Initial error: 0.0815
Final error: 0.0267
Image:  232
Initial error: 0.1244
Final error: 0.0274
Image:  233
Initial error: 0.1110
Final error: 0.0466
Image:  234
Initial error: 0.0692
Final error: 0.0919
Image:  235
Initial error: 0.1027
Final error: 0.0394
Image:  236
Initial error: 0.0527
Final error: 0.0480
Image:  237
Initial error: 0.0630
Final error: 0.0842
Image:  238
Initial error: 0.1269
Final error: 0.0394
Image:  239
Initial error: 0.0766
Final error: 0.0228
Image:  240
Initial error: 0.1092
Final error: 0.0720
Image:  241
Initial error: 0.0727
Final error: 0.0185
Image:  242
Initial error: 0.0782
Final error: 0.0324
Image:  243
Initial error: 0.0796
Final error: 0.0291
Image:  244
Initial error: 0.0994
Final error: 0.0348
Image:  245
Initial error: 0.0376
Final error: 0.0324
Image:  246
Initial error: 0.0545
Final error: 0.0175
Image:  247
Initial error: 0.1080
Final error: 0.0603
Image:  248
Initial error: 0.1178
Final error: 0.0536
Image:  249
Initial error: 0.1140
Final error: 0.0558
Image:  250
Initial error: 0.1153
Final error: 0.0242
Image:  251
Initial error: 0.1170
Final error: 0.0514
Image:  252
Initial error: 0.1311
Final error: 0.0416
Image:  253
Initial error: 0.0618
Final error: 0.0247
Image:  254
Initial error: 0.1027
Final error: 0.0317
Image:  255
Initial error: 0.0675
Final error: 0.0415
Image:  256
Initial error: 0.1118
Final error: 0.0359
Image:  257
Initial error: 0.0924
Final error: 0.0304
Image:  258
Initial error: 0.1101
Final error: 0.1787
Image:  259
Initial error: 0.0957
Final error: 0.0335
Image:  260
Initial error: 0.0829
Final error: 0.0253
Image:  261
Initial error: 0.0874
Final error: 0.0795
Image:  262
Initial error: 0.0695
Final error: 0.0288
Image:  263
Initial error: 0.1027
Final error: 0.0263
Image:  264
Initial error: 0.1006
Final error: 0.0239
Image:  265
Initial error: 0.0889
Final error: 0.0499
Image:  266
Initial error: 0.1084
Final error: 0.0190
Image:  267
Initial error: 0.1023
Final error: 0.0304
Image:  268
Initial error: 0.1084
Final error: 0.0483
Image:  269
Initial error: 0.0952
Final error: 0.0247
Image:  270
Initial error: 0.0519
Final error: 0.0209
Image:  271
Initial error: 0.1124
Final error: 0.0573
Image:  272
Initial error: 0.0664
Final error: 0.0303
Image:  273
Initial error: 0.0689
Final error: 0.0366
Image:  274
Initial error: 0.0888
Final error: 0.0245
Image:  275
Initial error: 0.0930
Final error: 0.0277
Image:  276
Initial error: 0.1163
Final error: 0.0270
Image:  277
Initial error: 0.1139
Final error: 0.0623
Image:  278
Initial error: 0.0796
Final error: 0.0183
Image:  279
Initial error: 0.0927
Final error: 0.0356
Image:  280
Initial error: 0.1299
Final error: 0.0434
Image:  281
Initial error: 0.0957
Final error: 0.0219
Image:  282
Initial error: 0.0981
Final error: 0.0221
Image:  283
Initial error: 0.1128
Final error: 0.0583
Image:  284
Initial error: 0.0799
Final error: 0.0273
Image:  285
Initial error: 0.1039
Final error: 0.0664
Image:  286
Initial error: 0.0962
Final error: 0.0250
Image:  287
Initial error: 0.0786
Final error: 0.0158
Image:  288
Initial error: 0.0703
Final error: 0.0215
Image:  289
Initial error: 0.0841
Final error: 0.0192
Image:  290
Initial error: 0.0853
Final error: 0.0251
Image:  291
Initial error: 0.1164
Final error: 0.0210
Image:  292
Initial error: 0.0886
Final error: 0.0289
Image:  293
Initial error: 0.1186
Final error: 0.0206
Image:  294
Initial error: 0.1195
Final error: 0.0228
Image:  295
Initial error: 0.0669
Final error: 0.0323
Image:  296
Initial error: 0.0575
Final error: 0.0317
Image:  297
Initial error: 0.1000
Final error: 0.0216
Image:  298
Initial error: 0.0640
Final error: 0.0387
Image:  299
Initial error: 0.0963
Final error: 0.0357
Image:  300
Initial error: 0.0889
Final error: 0.0347
Image:  301
Initial error: 0.1355
Final error: 0.0746
Image:  302
Initial error: 0.0610
Final error: 0.0292
Image:  303
Initial error: 0.0949
Final error: 0.0716
Image:  304
Initial error: 0.0957
Final error: 0.0269
Image:  305
Initial error: 0.0468
Final error: 0.0224
Image:  306
Initial error: 0.1013
Final error: 0.0261
Image:  307
Initial error: 0.1045
Final error: 0.0565
Image:  308
Initial error: 0.0806
Final error: 0.0152
Image:  309
Initial error: 0.0990
Final error: 0.0196
Image:  310
Initial error: 0.0713
Final error: 0.0792
Image:  311
Initial error: 0.1266
Final error: 0.0583
Image:  312
Initial error: 0.0793
Final error: 0.0345
Image:  313
Initial error: 0.0395
Final error: 0.0165
Image:  314
Initial error: 0.0668
Final error: 0.0257
Image:  315
Initial error: 0.0867
Final error: 0.0267
Image:  316
Initial error: 0.0445
Final error: 0.0328
Image:  317
Initial error: 0.0638
Final error: 0.0239
Image:  318
Initial error: 0.1074
Final error: 0.0293
Image:  319
Initial error: 0.1392
Final error: 0.0410
Image:  320
Initial error: 0.1332
Final error: 0.0238
Image:  321
Initial error: 0.1436
Final error: 0.1569
Image:  322
Initial error: 0.0808
Final error: 0.0366
Image:  323
Initial error: 0.0863
Final error: 0.0449
Image:  324
Initial error: 0.1229
Final error: 0.0258
Image:  325
Initial error: 0.0604
Final error: 0.0344
Image:  326
Initial error: 0.0822
Final error: 0.0327
Image:  327
Initial error: 0.1130
Final error: 0.0224
Image:  328
Initial error: 0.1069
Final error: 0.0725
Image:  329
Initial error: 0.0845
Final error: 0.1041
Image:  330
Initial error: 0.0876
Final error: 0.0406
Image:  331
Initial error: 0.0601
Final error: 0.0382
Image:  332
Initial error: 0.1017
Final error: 0.0741
Image:  333
Initial error: 0.0429
Final error: 0.0298
Image:  334
Initial error: 0.0924
Final error: 0.0333
Image:  335
Initial error: 0.1131
Final error: 0.0228
Image:  336
Initial error: 0.1436
Final error: 0.0540

Visualize Results


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


Save Results


In [18]:
from alabortcvpr2015.utils import pickle_dump

results = [fr.errors() for fr in fitter_results]

pickle_dump(results, '/data/PhD/Results/NONTAS_PIC_PARTSAAMs_AFW')

Timing

Total


In [13]:
%timeit fitter.fit(i, s, gt_shape=gt_s, max_iters=20)


10 loops, best of 3: 68.7 ms per loop

Per line


In [ ]:
import line_profiler
import IPython

ip = IPython.get_ipython()
ip.define_magic('lprun', line_profiler.magic_lprun)

In [ ]:
from alabortcvpr2015.aam import AIC

%lprun -f AIC.run fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Constrained Local Models

SVM Experts

Build


In [ ]:
from menpofast.feature import no_op, aam_dsift
from alabortcvpr2015.clm import CLMBuilder
from alabortcvpr2015.clm.classifier import LinearSVMLR 

offsets = np.meshgrid(range(-0, 1, 1), range(-0, 1, 1))
offsets = np.asarray([offsets[0].flatten(), offsets[1].flatten()]).T 

builder = CLMBuilder(parts_shape=(15, 15), features=aam_dsift2, diagonal=100, 
                     classifier=LinearSVMLR, offsets=offsets, normalize_parts=True, 
                     covariance=1, scale_shapes=False, scales=(1, .5))

clm = builder.build(training_images, group='ibug_face_66', verbose=True, 
                    threshold=0.015, dual=False, loss='l2', penalty='l1')

Test


In [ ]:
from alabortcvpr2015.clm import CLMFitter, RLMS
                  
fitter = CLMFitter(clm, n_shape=[3, 12], scale=100000, factor=100)

In [ ]:
np.random.seed(seed=1)

fitter_results = []

for j, i in enumerate(test_images):
    
    gt_s = i.landmarks['ibug_face_66'].lms
    s = fitter.perturb_shape(gt_s, noise_std=0.04)
    
    fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=True)
    
    fitter_results.append(fr)
    fr.downscale = 0.5
    
    print 'Image: ', j
    print fr

Visualize Results


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

Timing

Total


In [ ]:
%timeit fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Per line


In [ ]:
import line_profiler
import IPython

ip = IPython.get_ipython()
ip.define_magic('lprun', line_profiler.magic_lprun)

In [ ]:
from alabortcvpr2015.clm import RLMS

%lprun -f RLMS.run fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

MCF Experts

Build


In [ ]:
from menpofast.feature import no_op, aam_dsift, aam_daisy
from alabortcvpr2015.clm import CLMBuilder
from alabortcvpr2015.clm.classifier import MCF

offsets = np.meshgrid(range(-0, 1, 1), range(-0, 1, 1))
offsets = np.asarray([offsets[0].flatten(), offsets[1].flatten()]).T 

builder = CLMBuilder(parts_shape=(15, 15), features=aam_dsift, diagonal=100, 
                     classifier=MCF, offsets=offsets, normalize_parts=False, 
                     covariance=2, scale_shapes=False, scales=(1, .5))

clm = builder.build(training_images, group='ibug_face_66', verbose=True)

Test


In [ ]:
from alabortcvpr2015.clm import CLMFitter, RLMS
                  
fitter = CLMFitter(clm, n_shape=[3, 12], scale=100, factor=10)

In [ ]:
np.random.seed(seed=1)

fitter_results = []

for j, i in enumerate(test_images):
    
    gt_s = i.landmarks['ibug_face_66'].lms
    s = fitter.perturb_shape(gt_s, noise_std=0.05)
    
    fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=True)
    
    fitter_results.append(fr)
    fr.downscale = 0.5
    
    print 'Image: ', j
    print fr

Visualize Results


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

Timing

Total


In [ ]:
%timeit fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Per line


In [ ]:
import line_profiler
import IPython

ip = IPython.get_ipython()
ip.define_magic('lprun', line_profiler.magic_lprun)

In [ ]:
from alabortcvpr2015.clm import RLMS

%lprun -f RLMS.run fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Unified

Global

Build


In [ ]:
from menpofast.feature import no_op, aam_dsift, aam_daisy
from alabortcvpr2015.unified import GlobalUnifiedBuilder
from alabortcvpr2015.clm.classifier import MCF

offsets = np.meshgrid(range(-0, 1, 1), range(-0, 1, 1))
offsets = np.asarray([offsets[0].flatten(), offsets[1].flatten()]).T 

builder = GlobalUnifiedBuilder(parts_shape=(15, 15), features=aam_dsift, diagonal=100, 
                               classifier=MCF, offsets=offsets, normalize_parts=False, 
                               covariance=2, scale_shapes=False, scales=(1, .5))

unified = builder.build(training_images, group='ibug_face_66', verbose=True)

Test


In [ ]:
from alabortcvpr2015.unified import GlobalUnifiedFitter 
                  
fitter = GlobalUnifiedFitter(unified, n_shape=[3, 12], n_appearance=[25, 50], 
                             scale=1000, factor=10, sampling_step=8)

In [ ]:
np.random.seed(seed=1)

fitter_results = []

for j, i in enumerate(test_images):
    
    gt_s = i.landmarks['ibug_face_66'].lms
    s = fitter.perturb_shape(gt_s, noise_std=0.05)
    
    fr = fitter.fit(i, s, gt_shape=gt_s, max_iters=20, prior=True)
    
    fitter_results.append(fr)
    fr.downscale = 0.5
    
    print 'Image: ', j
    print fr

Visualize Results


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

Timing

Total


In [ ]:
%timeit fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Per line


In [ ]:
import line_profiler
import IPython

ip = IPython.get_ipython()
ip.define_magic('lprun', line_profiler.magic_lprun)

In [ ]:
from alabortcvpr2015.unified import ProbAIC

%lprun -f ProbAIC.run fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Parts

Build


In [ ]:
from menpofast.feature import no_op, aam_dsift, aam_daisy
from alabortcvpr2015.unified import PartsUnifiedBuilder
from alabortcvpr2015.clm.classifier import MCF

offsets = np.meshgrid(range(-0, 1, 1), range(-0, 1, 1))
offsets = np.asarray([offsets[0].flatten(), offsets[1].flatten()]).T 

builder = PartsUnifiedBuilder(parts_shape=(15, 15), features=aam_dsift, diagonal=100, 
                              classifier=MCF, offsets=offsets, normalize_parts=False, 
                              covariance=2, scale_shapes=False, scales=(1, .5))

unified = builder.build(training_images, group='ibug_face_66', verbose=True)

Test


In [ ]:
sampling_mask = np.require(np.zeros((15, 15)), dtype=np.bool)
sampling_mask[1::4, 1::4] = True
#sampling_mask[:] = True

imshow(sampling_mask)

In [ ]:
from alabortcvpr2015.unified import PartsUnifiedFitter 
                  
fitter = PartsUnifiedFitter(unified, n_shape=[3, 12], n_appearance=[25, 50], 
                            scale=100000, factor=100, sampling_mask=sampling_mask)

In [ ]:
fitter._algorithms[0]._sigma2=10000
fitter._algorithms[1]._sigma2=10000
fitter._algorithms[0]._rho2=0
fitter._algorithms[1]._rho2=0

In [ ]:
np.random.seed(seed=1)

fitter_results = []

for j, i in enumerate(test_images):
    
    gt_s = i.landmarks['ibug_face_66'].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

Visualize Results


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

Timing

Total


In [ ]:
%timeit fitter.fit(i, s, gt_shape=gt_s, max_iters=20)

Per line


In [ ]:
import line_profiler
import IPython

ip = IPython.get_ipython()
ip.define_magic('lprun', line_profiler.magic_lprun)

In [ ]:
from alabortcvpr2015.unified import ProbAIC

%lprun -f ProbAIC.run fitter.fit(i, s, gt_shape=gt_s, max_iters=20)