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)
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)
In [5]:
import hickle
hickle.dump(model, "../models/"+MODEL_NAME)
In [8]:
print "Mean initial error: {}".format(np.mean(initial_errors))
print "Mean final error: {}".format(np.mean(final_errors))
In [9]:
from menpofit.visualize import plot_ced
plot_ced(final_errors)
In [10]:
worst = np.argmax(final_errors)
worst
Out[10]:
In [11]:
i = worst
In [12]:
final_shapes[i].view()
test_images[i].view()
Out[12]: