ert



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.test.end2end import test_model
from facefit import util

In [2]:
MODEL_NAME = "ert_lfpw_helen.hkl"

In [3]:
lfpw_train = util.read_images("../datasets/lfpw/trainset/", normalise=True)
lfpw_test = util.read_images("../datasets/lfpw/testset/", normalise=True)
helen_train = util.read_images("../datasets/helen_cropped/trainset_cropped", normalise=True)
helen_test = util.read_images("../datasets/helen_cropped/testset_cropped/", normalise=True)


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

In [4]:
train_images = np.concatenate([lfpw_train, helen_train])
test_images = np.concatenate([lfpw_test, helen_test])

In [ ]:
builder = ert.ERTBuilder(n_stages=10, n_trees=500, MU=0.1, n_perturbations=20)

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: 56240 images.

Building primitive regressor 499
Built outer regressor 0

Building primitive regressor 499
Built outer regressor 1

Building primitive regressor 499
Built outer regressor 2

Building primitive regressor 499
Built outer regressor 3

Building primitive regressor 499
Built outer regressor 4

Building primitive regressor 499
Built outer regressor 6

Building primitive regressor 499
Built outer regressor 7

Building primitive regressor 499
Built outer regressor 8

Building primitive regressor 499
Built outer regressor 9

554/554

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


dumping <class 'facefit.cascade.CascadedShapeRegressor'> to file <HDF5 file "ert_lfpw_helen.hkl" (mode r+)>
Warning: <class 'facefit.cascade.CascadedShapeRegressor'> 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.10884353332
Mean final error: 0.0250875900938

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



In [11]:
initial_errors, final_errors, initial_shapes, final_shapes = test_model(model, test_images, num_init=5)


554/554

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


Mean initial error: 0.10884353332
Mean final error: 0.0244959409631

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



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


Out[7]:
204

In [14]:
initial_errors, final_errors, initial_shapes, final_shapes = test_model(model, lfpw_test, num_init=1)


224/224

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


Mean initial error: 0.102570194775
Mean final error: 0.0229567728497

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



In [17]:
initial_errors, final_errors, initial_shapes, final_shapes = test_model(model, lfpw_test, num_init=5)
print "Mean initial error: {}".format(np.mean(initial_errors))
print "Mean final error: {}".format(np.mean(final_errors))


224/224Mean initial error: 0.102570194775
Mean final error: 0.0220748214165

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



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


Out[13]:
<menpo.visualize.viewmatplotlib.MatplotlibImageViewer2d at 0x7fc24c8be990>

In [14]:
initial_shapes[i].view()
test_images[i].view()


Out[14]:
<menpo.visualize.viewmatplotlib.MatplotlibImageViewer2d at 0x7fc24cf28f90>

In [ ]: