In [13]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['seed', 'repeat']
`%matplotlib` prevents importing * from pylab and numpy

In [14]:
repeat = 1

Load test data


In [15]:
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'

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


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

In [16]:
from menpo.visualize import visualize_images

visualize_images(test_images)


CLMs

Load


In [17]:
from alabortcvpr2015.utils import pickle_load

aam = pickle_load(path + 'PhD/Models/clm_lfpw_fast_dsift')

AIC


In [18]:
from alabortcvpr2015.clm import CLMFitter, RLMS
                  
fitter = CLMFitter(aam, algorithm_cls=RLMS, n_shape=[3, 12])

In [19]:
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


Image:  0
Initial error: 0.1847
Final error: 0.0171
Image:  1
Initial error: 0.1086
Final error: 0.0223
Image:  2
Initial error: 0.0730
Final error: 0.0480
Image:  3
Initial error: 0.0574
Final error: 0.0195
Image:  4
Initial error: 0.0662
Final error: 0.0197
Image:  5
Initial error: 0.1399
Final error: 0.0228
Image:  6
Initial error: 0.0868
Final error: 0.0277
Image:  7
Initial error: 0.1125
Final error: 0.0330
Image:  8
Initial error: 0.0627
Final error: 0.0206
Image:  9
Initial error: 0.0298
Final error: 0.0185
Image:  10
Initial error: 0.1454
Final error: 0.0431
Image:  11
Initial error: 0.0880
Final error: 0.0208
Image:  12
Initial error: 0.1057
Final error: 0.0152
Image:  13
Initial error: 0.0356
Final error: 0.0112
Image:  14
Initial error: 0.0950
Final error: 0.0219
Image:  15
Initial error: 0.1339
Final error: 0.0259
Image:  16
Initial error: 0.0899
Final error: 0.0216
Image:  17
Initial error: 0.0720
Final error: 0.0387
Image:  18
Initial error: 0.0629
Final error: 0.0279
Image:  19
Initial error: 0.0592
Final error: 0.0317
Image:  20
Initial error: 0.1301
Final error: 0.0222
Image:  21
Initial error: 0.1056
Final error: 0.0307
Image:  22
Initial error: 0.0790
Final error: 0.0225
Image:  23
Initial error: 0.0511
Final error: 0.0185
Image:  24
Initial error: 0.0600
Final error: 0.0322
Image:  25
Initial error: 0.1091
Final error: 0.0200
Image:  26
Initial error: 0.1060
Final error: 0.0197
Image:  27
Initial error: 0.1797
Final error: 0.0277
Image:  28
Initial error: 0.0524
Final error: 0.0215
Image:  29
Initial error: 0.0953
Final error: 0.0173
Image:  30
Initial error: 0.0817
Final error: 0.0170
Image:  31
Initial error: 0.0857
Final error: 0.0154
Image:  32
Initial error: 0.0625
Final error: 0.0260
Image:  33
Initial error: 0.0688
Final error: 0.0245
Image:  34
Initial error: 0.0741
Final error: 0.0305
Image:  35
Initial error: 0.0680
Final error: 0.0235
Image:  36
Initial error: 0.1298
Final error: 0.0345
Image:  37
Initial error: 0.0789
Final error: 0.0290
Image:  38
Initial error: 0.0822
Final error: 0.0303
Image:  39
Initial error: 0.0792
Final error: 0.0498
Image:  40
Initial error: 0.0983
Final error: 0.0245
Image:  41
Initial error: 0.1618
Final error: 0.0794
Image:  42
Initial error: 0.0968
Final error: 0.0317
Image:  43
Initial error: 0.0800
Final error: 0.0317
Image:  44
Initial error: 0.0682
Final error: 0.0288
Image:  45
Initial error: 0.1432
Final error: 0.0285
Image:  46
Initial error: 0.0803
Final error: 0.0354
Image:  47
Initial error: 0.0908
Final error: 0.0165
Image:  48
Initial error: 0.0401
Final error: 0.0280
Image:  49
Initial error: 0.1610
Final error: 0.0524
Image:  50
Initial error: 0.0515
Final error: 0.0204
Image:  51
Initial error: 0.0543
Final error: 0.0432
Image:  52
Initial error: 0.0547
Final error: 0.0305
Image:  53
Initial error: 0.1048
Final error: 0.0404
Image:  54
Initial error: 0.1050
Final error: 0.0508
Image:  55
Initial error: 0.0816
Final error: 0.0211
Image:  56
Initial error: 0.0755
Final error: 0.0357
Image:  57
Initial error: 0.1143
Final error: 0.0215
Image:  58
Initial error: 0.0855
Final error: 0.0384
Image:  59
Initial error: 0.0919
Final error: 0.0257
Image:  60
Initial error: 0.0633
Final error: 0.0170
Image:  61
Initial error: 0.0770
Final error: 0.0679
Image:  62
Initial error: 0.0653
Final error: 0.0262
Image:  63
Initial error: 0.1445
Final error: 0.0377
Image:  64
Initial error: 0.1038
Final error: 0.0283
Image:  65
Initial error: 0.1567
Final error: 0.0447
Image:  66
Initial error: 0.0865
Final error: 0.0495
Image:  67
Initial error: 0.1748
Final error: 0.0600
Image:  68
Initial error: 0.0584
Final error: 0.0249
Image:  69
Initial error: 0.1486
Final error: 0.0633
Image:  70
Initial error: 0.0834
Final error: 0.0180
Image:  71
Initial error: 0.0859
Final error: 0.0173
Image:  72
Initial error: 0.0542
Final error: 0.0202
Image:  73
Initial error: 0.1554
Final error: 0.0331
Image:  74
Initial error: 0.0458
Final error: 0.0211
Image:  75
Initial error: 0.1024
Final error: 0.0162
Image:  76
Initial error: 0.0873
Final error: 0.0203
Image:  77
Initial error: 0.1316
Final error: 0.0402
Image:  78
Initial error: 0.0756
Final error: 0.0188
Image:  79
Initial error: 0.0315
Final error: 0.0221
Image:  80
Initial error: 0.0909
Final error: 0.0220
Image:  81
Initial error: 0.0870
Final error: 0.0177
Image:  82
Initial error: 0.0990
Final error: 0.0536
Image:  83
Initial error: 0.1552
Final error: 0.0266
Image:  84
Initial error: 0.1218
Final error: 0.0242
Image:  85
Initial error: 0.0552
Final error: 0.0265
Image:  86
Initial error: 0.0448
Final error: 0.0269
Image:  87
Initial error: 0.0861
Final error: 0.0369
Image:  88
Initial error: 0.0346
Final error: 0.0226
Image:  89
Initial error: 0.0908
Final error: 0.0201
Image:  90
Initial error: 0.0733
Final error: 0.0253
Image:  91
Initial error: 0.0553
Final error: 0.0303
Image:  92
Initial error: 0.0793
Final error: 0.0173
Image:  93
Initial error: 0.0526
Final error: 0.0170
Image:  94
Initial error: 0.0964
Final error: 0.0556
Image:  95
Initial error: 0.1957
Final error: 0.0353
Image:  96
Initial error: 0.1034
Final error: 0.0421
Image:  97
Initial error: 0.0916
Final error: 0.0162
Image:  98
Initial error: 0.0763
Final error: 0.0198
Image:  99
Initial error: 0.1203
Final error: 0.0225
Image:  100
Initial error: 0.0593
Final error: 0.0350
Image:  101
Initial error: 0.0919
Final error: 0.0343
Image:  102
Initial error: 0.0860
Final error: 0.0267
Image:  103
Initial error: 0.0853
Final error: 0.0217
Image:  104
Initial error: 0.1238
Final error: 0.0267
Image:  105
Initial error: 0.0939
Final error: 0.0243
Image:  106
Initial error: 0.1568
Final error: 0.0308
Image:  107
Initial error: 0.1161
Final error: 0.0381
Image:  108
Initial error: 0.0754
Final error: 0.0479
Image:  109
Initial error: 0.0615
Final error: 0.0252
Image:  110
Initial error: 0.0379
Final error: 0.0290
Image:  111
Initial error: 0.0810
Final error: 0.0309
Image:  112
Initial error: 0.0864
Final error: 0.0224
Image:  113
Initial error: 0.1303
Final error: 0.0393
Image:  114
Initial error: 0.0514
Final error: 0.0358
Image:  115
Initial error: 0.0537
Final error: 0.0198
Image:  116
Initial error: 0.1014
Final error: 0.0233
Image:  117
Initial error: 0.2082
Final error: 0.0217
Image:  118
Initial error: 0.0857
Final error: 0.0280
Image:  119
Initial error: 0.1389
Final error: 0.0326
Image:  120
Initial error: 0.1172
Final error: 0.0432
Image:  121
Initial error: 0.1187
Final error: 0.0350
Image:  122
Initial error: 0.0649
Final error: 0.0168
Image:  123
Initial error: 0.1760
Final error: 0.1966
Image:  124
Initial error: 0.0869
Final error: 0.0211
Image:  125
Initial error: 0.0677
Final error: 0.0147
Image:  126
Initial error: 0.1445
Final error: 0.0894
Image:  127
Initial error: 0.0794
Final error: 0.0635
Image:  128
Initial error: 0.0960
Final error: 0.0437
Image:  129
Initial error: 0.1203
Final error: 0.0476
Image:  130
Initial error: 0.1228
Final error: 0.0339
Image:  131
Initial error: 0.1002
Final error: 0.0214
Image:  132
Initial error: 0.1948
Final error: 0.0209
Image:  133
Initial error: 0.0612
Final error: 0.0334
Image:  134
Initial error: 0.0597
Final error: 0.0165
Image:  135
Initial error: 0.0936
Final error: 0.0234
Image:  136
Initial error: 0.1467
Final error: 0.0565
Image:  137
Initial error: 0.0828
Final error: 0.0352
Image:  138
Initial error: 0.1059
Final error: 0.0245
Image:  139
Initial error: 0.2043
Final error: 0.0773
Image:  140
Initial error: 0.0826
Final error: 0.0242
Image:  141
Initial error: 0.0361
Final error: 0.0245
Image:  142
Initial error: 0.1122
Final error: 0.0416
Image:  143
Initial error: 0.0557
Final error: 0.0225
Image:  144
Initial error: 0.0496
Final error: 0.0226
Image:  145
Initial error: 0.1429
Final error: 0.0394
Image:  146
Initial error: 0.0770
Final error: 0.0327
Image:  147
Initial error: 0.0534
Final error: 0.0275
Image:  148
Initial error: 0.0341
Final error: 0.0235
Image:  149
Initial error: 0.0829
Final error: 0.0219
Image:  150
Initial error: 0.1012
Final error: 0.0253
Image:  151
Initial error: 0.1540
Final error: 0.0320
Image:  152
Initial error: 0.1131
Final error: 0.0177
Image:  153
Initial error: 0.0473
Final error: 0.0225
Image:  154
Initial error: 0.1071
Final error: 0.0323
Image:  155
Initial error: 0.0357
Final error: 0.0223
Image:  156
Initial error: 0.0757
Final error: 0.0220
Image:  157
Initial error: 0.0610
Final error: 0.0211
Image:  158
Initial error: 0.0720
Final error: 0.0246
Image:  159
Initial error: 0.0709
Final error: 0.0320
Image:  160
Initial error: 0.0804
Final error: 0.0262
Image:  161
Initial error: 0.0709
Final error: 0.0627
Image:  162
Initial error: 0.1497
Final error: 0.0225
Image:  163
Initial error: 0.0722
Final error: 0.0332
Image:  164
Initial error: 0.1257
Final error: 0.0691
Image:  165
Initial error: 0.0414
Final error: 0.0306
Image:  166
Initial error: 0.0502
Final error: 0.0307
Image:  167
Initial error: 0.1911
Final error: 0.0203
Image:  168
Initial error: 0.1134
Final error: 0.0285
Image:  169
Initial error: 0.0632
Final error: 0.0272
Image:  170
Initial error: 0.0375
Final error: 0.0164
Image:  171
Initial error: 0.1844
Final error: 0.0613
Image:  172
Initial error: 0.0638
Final error: 0.0412
Image:  173
Initial error: 0.0798
Final error: 0.0524
Image:  174
Initial error: 0.0538
Final error: 0.0230
Image:  175
Initial error: 0.1046
Final error: 0.0464
Image:  176
Initial error: 0.0492
Final error: 0.0218
Image:  177
Initial error: 0.0754
Final error: 0.0183
Image:  178
Initial error: 0.0617
Final error: 0.0312
Image:  179
Initial error: 0.0669
Final error: 0.0253
Image:  180
Initial error: 0.0565
Final error: 0.0289
Image:  181
Initial error: 0.1021
Final error: 0.0233
Image:  182
Initial error: 0.0536
Final error: 0.0327
Image:  183
Initial error: 0.1725
Final error: 0.0388
Image:  184
Initial error: 0.0584
Final error: 0.0225
Image:  185
Initial error: 0.0894
Final error: 0.0290
Image:  186
Initial error: 0.0444
Final error: 0.0250
Image:  187
Initial error: 0.1490
Final error: 0.0253
Image:  188
Initial error: 0.0609
Final error: 0.0282
Image:  189
Initial error: 0.0809
Final error: 0.0230
Image:  190
Initial error: 0.0464
Final error: 0.0224
Image:  191
Initial error: 0.0511
Final error: 0.0395
Image:  192
Initial error: 0.0689
Final error: 0.0423
Image:  193
Initial error: 0.1389
Final error: 0.0241
Image:  194
Initial error: 0.0918
Final error: 0.0221
Image:  195
Initial error: 0.0948
Final error: 0.0270
Image:  196
Initial error: 0.0534
Final error: 0.0214
Image:  197
Initial error: 0.1021
Final error: 0.0357
Image:  198
Initial error: 0.1164
Final error: 0.0244
Image:  199
Initial error: 0.0607
Final error: 0.0191
Image:  200
Initial error: 0.0668
Final error: 0.0318
Image:  201
Initial error: 0.0642
Final error: 0.0256
Image:  202
Initial error: 0.1165
Final error: 0.0385
Image:  203
Initial error: 0.1328
Final error: 0.0254
Image:  204
Initial error: 0.1077
Final error: 0.0275
Image:  205
Initial error: 0.0660
Final error: 0.0318
Image:  206
Initial error: 0.0968
Final error: 0.0273
Image:  207
Initial error: 0.1018
Final error: 0.0197
Image:  208
Initial error: 0.0561
Final error: 0.0268
Image:  209
Initial error: 0.0567
Final error: 0.0543
Image:  210
Initial error: 0.1288
Final error: 0.0260
Image:  211
Initial error: 0.0566
Final error: 0.0186
Image:  212
Initial error: 0.1968
Final error: 0.0299
Image:  213
Initial error: 0.0903
Final error: 0.0362
Image:  214
Initial error: 0.1032
Final error: 0.0200
Image:  215
Initial error: 0.0553
Final error: 0.0200
Image:  216
Initial error: 0.0484
Final error: 0.0195
Image:  217
Initial error: 0.0866
Final error: 0.0209
Image:  218
Initial error: 0.0783
Final error: 0.0139
Image:  219
Initial error: 0.1155
Final error: 0.0180
Image:  220
Initial error: 0.0522
Final error: 0.0200
Image:  221
Initial error: 0.0653
Final error: 0.0143
Image:  222
Initial error: 0.0568
Final error: 0.0147
Image:  223
Initial error: 0.1383
Final error: 0.0304

Visualize Results


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


Save Results


In [21]:
from alabortcvpr2015.utils import pickle_dump
from alabortcvpr2015.result import SerializableResult

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

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

Timing

Total


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


10 loops, best of 3: 118 ms per loop

Per line


In [23]:
import line_profiler
import IPython

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

In [24]:
from alabortcvpr2015.aam import AIC

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