example



In [1]:
import site
site.addsitedir('..')
import menpo.io as mio
import menpodetect
import numpy as np
import facefit
%matplotlib inline
from facefit import esr, ert, lbf
from facefit.test import fit_all
from facefit import util

In [2]:
TRAINSET = "../datasets/examples"
TESTSET = "../datasets/examples"
MODEL_NAME = "esr_model_examples.hkl"

In [3]:
train_images = util.read_images(TRAINSET, normalise=True)
test_images = util.read_images(TESTSET, normalise=True)


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

In [6]:
builder = facefit.esr.ESRBuilder(n_landmarks=68, n_stages=10, n_ferns=500, beta=1000, 
                                 n_perturbations=1, compress_ferns=True)

# builder = ert.ERTBuilder(n_stages=10, n_trees=500, MU=0.1, n_perturbations=20)

# builder = lbf.LBFBuilder(n_stages=5, n_trees=300, tree_depth=5, n_perturbations=20, MU=0)

initial_errors, final_errors, initial_shapes, final_shapes, model = fit_all(builder, train_images, test_images, num_init=1)


Perturbing initial estimates
Size of augmented dataset: 20 images.

Building primitive regressor 49
Built outer regressor 0

20/20

In [5]:
import hickle
hickle.dump(model, "../models/"+MODEL_NAME)


dumping <type 'instance'> to file <HDF5 file "esr_model_examples.hkl" (mode r+)>
Warning: <type 'instance'> type not understood, data have been serialized

In [8]:
print "Mean initial error: {}".format(np.mean(initial_errors))
print "Mean final error: {}".format(np.mean(final_errors))


Mean initial error: 0.100568170806
Mean final error: 1.06063003196e-13

In [9]:
from menpofit.visualize import plot_ced
plot_ced(final_errors)



In [10]:
worst = np.argmax(final_errors)
worst


Out[10]:
14

In [11]:
i = worst

In [12]:
final_shapes[i].view()
test_images[i].view()


Out[12]:
<menpo.visualize.viewmatplotlib.MatplotlibImageViewer2d at 0x108be3850>