Back to paper library
Paper notesCVPR 2014

ERT

Five Thousand Trees

Original paper

One Millisecond Face Alignment with an Ensemble of Regression Trees

Paper authors

Vahid Kazemi · Josephine Sullivan

Publication
CVPR 2014Conference
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@inproceedings{faceanalysisert2014,
  title = {{One Millisecond Face Alignment with an Ensemble of Regression Trees}},
  author = {Vahid Kazemi and Josephine Sullivan},
  year = {2014},
  booktitle = {CVPR},
  url = {https://openaccess.thecvf.com/content_cvpr_2014/html/Kazemi_One_Millisecond_Face_2014_CVPR_paper.html}
}
On this page

shape_predictor_68_face_landmarks.dat is a file plenty of people downloaded long before they had ever heard of ERT.

It is dlib's facial landmark model. Hand it a photo and a face box, and it returns 68 points laid out along the jaw, the eyebrows, the nose, the eyes and the lips. Face-swap effects, drowsiness detection, virtual try-on: in many tutorials and projects, step one is loading this file. In August 2014, dlib's author Davis King announced v18.10 on the dlib blog, and its headline new feature was an implementation of this paper from that year's CVPR.

The paper comes from Vahid Kazemi and Josephine Sullivan at KTH Royal Institute of Technology in Sweden, and the title puts the speed right up front, one millisecond. The cascaded regression of the time (ESR) recommended running from several random starting points and taking the median; this paper runs once from a single mean face, gets a lower error on HELEN's 194 points, and needs an order of magnitude less computation.

There's no convolution in it, and no GPU. The whole model is ten levels of five hundred regression trees each, and every node in every tree only checks whether the brightness difference between two pixels exceeds a threshold.

Defining the Problem

What face alignment does

Face alignment takes an image and a face box and outputs a set of landmark coordinates. Stack the x,yx, y of pp points into a 2p2p-dimensional vector, which the paper calls the shape:

S=(x1T,x2T,…,xpT)T∈R2pS = (x_1^T, x_2^T, \dots, x_p^T)^T \in \mathbb R^{2p}

How many points there are depends on how the dataset is annotated. The 68 points that later became the most common are the 300-W format: 17 on the jaw contour, 10 on the eyebrows, 9 on the nose, 12 on the eyes and 20 on the mouth. HELEN, which this paper mainly uses, is annotated more densely, with 194 points per face and several dozen each on the lips and the jaw alone, so SS has 388 dimensions.

How is the error measured? Average each point's distance to the ground truth, then divide by the distance between the two eyes; that is NME (normalized mean error). Dividing by the eye distance lets large and small faces be compared together. A face whose eyes are 100 pixels apart, with points off by 4.9 pixels on average, has an NME of 0.049; a face whose eyes are 50 pixels apart, off by 2.45 pixels on average, also comes to 0.049.

The choice of denominator changes the numbers directly. Some papers use the distance between the two pupils, others the distance between the two outer eye corners. Suppose a face has its pupils 60 pixels apart and its outer eye corners 84 pixels apart. With the same average error of 3 pixels, the first gives 5% and the second 3.6%. Before putting tables from different papers side by side, check the denominator.

Chicken and egg

The early mainstream was the Active Shape Model (ASM) and the Active Appearance Model (AAM). They first compress the training shapes into a few principal components with PCA, then at inference keep adjusting those coefficients until the shape fits the image. A high-dimensional nonconvex problem has many local optima, and restricting the search to the PCA subspace avoids a lot of wrong turns, but iterative fitting is slow and gets stuck when the starting point is bad.

After 2010 the field switched to cascaded regression. Start from an initial shape (usually the mean face shape); at each stage, look at the image, predict a correction, add it, and hand the result to the next stage. Dollár et al.'s CPR and Cao et al.'s ESR both follow this route.

There's a dilemma here, which the authors spell out in the introduction. To estimate the shape accurately you need reliable features, and to get reliable features you first need to know where the shape is. The same pixel coordinate (120,85)(120, 85) is an eye corner on one face and may be a cheek on another face whose head is turned.

Cascaded regression gets around this with shape-indexed features. A pixel location isn't written in absolute image coordinates but "relative to some landmark of the current estimate." The more accurate the current shape estimate, the closer the sampled pixels are to the same semantic location, and the more accurate the next stage's prediction.

ESR uses these features too, comparing the brightness difference of two pixels. Its regressors are ferns (a simplified decision tree that applies the same test at every level), and it picks features by correlation. To reduce the dependence on the initial shape, ESR recommends running from several random initial shapes and taking the median.

What this paper wants to know is whether, with the same pixel differences, a single run from the mean face shape can be more accurate than ten.

Solving the Problem

Ten rounds of correction from the mean face shape

Original Figure 2: the same HELEN face photo in six panels. The first five are cascade levels 0, 1, 2, 3 and 10, with yellow dots showing the 194-point estimate at that level; the last panel shows the ground truth in green. Level 0 is the mean face shape placed at the center of the face box, with the jaw contour and the eyebrows clearly off; after level 1 the contour roughly fits the face, and level 10 almost coincides with the ground truth.
Original Figure 2, Kazemi and Sullivan, from PDF page 5 of the CVPR 2014 open-access version, scholarly quotation.

Panel 0 is the starting point. A detector produces a face box (this figure uses the Viola & Jones detector), and the mean face shape of the training data is scaled and shifted to the center of the box. This face is turned slightly, so the mean shape's jaw contour and eyebrows are clearly off.

What each level does fits on one line:

S^(t+1)=S^(t)+rt(I,S^(t))\hat S^{(t+1)} = \hat S^{(t)} + r_t\left(I, \hat S^{(t)}\right)

S^(t)\hat S^{(t)} is the estimate at level tt, II is the image, and rtr_t is the level-tt regressor, which outputs a 388-dimensional correction. After level 1 the contour roughly fits the face, the later levels only fine-tune details, and level 10 almost coincides with the ground truth. The paper uses T=10T=10 levels.

How the training data is made

To learn r0r_0, you need pairs of "current estimate" and "where to move." The paper builds triplets from nn annotated images:

(Iπi, S^i(0), ΔSi(0)),ΔSi(0)=Sπi−S^i(0)\left(I_{\pi_i},\ \hat S_i^{(0)},\ \Delta S_i^{(0)}\right),\quad \Delta S_i^{(0)} = S_{\pi_i} - \hat S_i^{(0)}

IπiI_{\pi_i} is one of the training images and SπiS_{\pi_i} is its ground truth; the initial shape S^i(0)\hat S_i^{(0)} is the ground-truth shape of another training image, and ΔSi(0)\Delta S_i^{(0)} is the correction to learn. Each image is paired with R=20R=20 different initial shapes, so 2,000 HELEN training images become 40,000 samples.

At test time it always starts from the mean face shape, yet training deliberately starts from all sorts of other people's face shapes. The regressor therefore sees every kind of mistake, a start that's too wide, a start that's too flat, a mouth placed too low, and learns how to fix a shape that's off. This is a form of data augmentation as well, and the ablations later show how much it can make up for.

Once r0r_0 is learned, apply it to every sample to get new estimates and new residuals, which become the training data for r1r_1:

S^i(t+1)=S^i(t)+rt(Iπi,S^i(t))ΔSi(t+1)=Sπi−S^i(t+1)\begin{aligned} \hat S_i^{(t+1)} &= \hat S_i^{(t)} + r_t\left(I_{\pi_i}, \hat S_i^{(t)}\right)\\ \Delta S_i^{(t+1)} &= S_{\pi_i} - \hat S_i^{(t+1)} \end{aligned}

And so on, all the way to r9r_9.

Each level is gradient boosting over 500 trees

Each rtr_t is itself a gradient boosting ensemble, the sum of K=500K=500 regression trees. The procedure is the paper's Algorithm 1:

  1. Start from a constant vector, with f0f_0 set to the mean of the corrections ΔSi\Delta S_i over all samples.
  2. Tree kk fits whatever hasn't been explained yet, the residual rik=ΔSi−fk−1(Iπi,S^i)r_{ik} = \Delta S_i - f_{k-1}(I_{\pi_i}, \hat S_i).
  3. Fit a tree gkg_k, multiply it by the learning rate ν\nu and add it in, fk=fk−1+ν gkf_k = f_{k-1} + \nu\, g_k.

The loss is squared error, and the negative gradient of squared error is exactly the residual, so every tree chases the error that's left.

Let's run the numbers for one coordinate. Suppose that across four training samples, the xx corrections of the left mouth corner are +6,+4,−2,−4+6, +4, -2, -4 pixels. f0f_0 is the mean, +1+1, and the residuals become +5,+3,−3,−5+5, +3, -3, -5. If the first tree puts the first two in the left leaf and the last two in the right leaf, the leaf values are the means of each side, +4+4 and −4-4. The paper uses ν=0.1\nu = 0.1, so this tree actually adds only +0.4+0.4 and −0.4-0.4, leaving residuals of +4.6,+2.6,−2.6,−4.6+4.6, +2.6, -2.6, -4.6.

Each tree takes only a small step and leaves the rest to the trees after it. This is called shrinkage, and it keeps the first few trees from overfitting the training data; the ablations later show the error doubling without it.

Pixel differences have to follow the face

Each split node of a tree makes exactly one comparison:

h(Iπi,S^i(t),θ)={1Iπi(u′)−Iπi(v′)>τ0otherwiseh\left(I_{\pi_i}, \hat S_i^{(t)}, \theta\right) = \begin{cases} 1 & I_{\pi_i}(u') - I_{\pi_i}(v') > \tau\\ 0 & \text{otherwise} \end{cases}

θ=(τ,u,v)\theta = (\tau, u, v) are the split's parameters, two pixel positions and a threshold.

Why compare the difference of two pixels instead of comparing a single pixel against a threshold? Suppose I(u′)=120I(u') = 120, I(v′)=90I(v') = 90 and the threshold is τ=20\tau = 20. The difference is 30, so the sample goes left. Brighten the whole photo by 40 and the two pixels become 160 and 130; the difference is still 30, and it still goes left. A single-pixel test flips when the whole image gets brighter or darker, while a pixel difference is unaffected.

The trouble is that uu and vv are chosen in the coordinate system of the mean face shape, while real faces vary in size, tilt and position. Ideally you would warp the whole image onto the mean face shape before sampling pixels, but each level reads only 400 points, so warping the whole image is a waste. The authors warp only the positions of those few points.

Schematic drawn for this note, in two panels. The left panel shows the five blue points of the mean face shape (two eyes, nose tip, two mouth corners) inside a dashed outline; the orange pixel u sits above and to the right of the left eye, with the arrow labeled δu = u − left eye = (6, −8); the purple pixel v sits below and to the left of the nose tip, δv = v − nose tip = (−8, 6). The right panel shows the same shape scaled up 2× and rotated 20 degrees clockwise, its outline larger and tilted; the orange u′ is still above and to the right of the left eye, offset by about (16.7, −10.9), and the purple v′ is still below and to the left of the nose tip, offset by about (−19.1, 5.8). The bottom line reads: split test, go left if I(u′) − I(v′) > τ, else go right.
Drawn for this note from equations (7)–(9) of the paper.

On the left is the mean face shape. We place five points in 100×100100\times100 normalized coordinates, with the left eye (the one on the left side of the image) at (35,40)(35, 40) and the nose tip at (50,60)(50, 60). The two pixels the tree picked are u=(41,32)u = (41, 32) and v=(42,66)v = (42, 66).

First, for each pixel, find the nearest landmark kuk_u on the mean face shape and record the offset:

δxu=u−xˉku\delta x_u = u - \bar x_{k_u}

The landmark nearest uu is the left eye, δxu=(6,−8)\delta x_u = (6, -8); the one nearest vv is the nose tip, δxv=(−8,6)\delta x_v = (-8, 6). This step is done at training time and stored in the model.

Second, on the test image, find a similarity transform (rotation, uniform scaling, translation) that maps the current shape estimate S^\hat S onto the mean face shape Sˉ\bar S, minimizing the squared distance between the two point sets:

∑j=1p∥xˉj−(siRi xi,j+ti)∥2\sum_{j=1}^{p}\left\| \bar x_j - \left(s_i R_i\, x_{i,j} + t_i\right) \right\|^2

sis_i is the scale, RiR_i the rotation matrix and tit_i the translation.

Third, carry the offset back onto the image by running this transform in reverse:

u′=xi,ku+1siRiT δxuu' = x_{i,k_u} + \frac{1}{s_i} R_i^T\, \delta x_u

xi,kux_{i,k_u} is the position of the left eye in the current estimate. The face on the right is twice the size of the mean face shape and rotated 20 degrees clockwise, so mapping it back onto the mean face shape means shrinking it by half and rotating it 20 degrees counterclockwise: si=0.5s_i = 0.5, and RiR_i is a 20-degree counterclockwise rotation. Run in reverse, 1siRiT\frac{1}{s_i}R_i^T scales up by two and rotates 20 degrees clockwise:

2(cos⁡20∘−sin⁡20∘sin⁡20∘cos⁡20∘)(6−8)≈(16.7−10.9)\begin{aligned} &2\begin{pmatrix}\cos 20^\circ & -\sin 20^\circ\\ \sin 20^\circ & \cos 20^\circ\end{pmatrix}\begin{pmatrix}6\\-8\end{pmatrix}\\ &\quad\approx \begin{pmatrix}16.7\\-10.9\end{pmatrix} \end{aligned}

In image coordinates the yy axis points down, so on screen this matrix rotates clockwise. If the current estimate puts the left eye at (180,160)(180, 160), u′u' lands at (196.7,149.1)(196.7, 149.1), and rounding reads the pixel at (197,149)(197, 149). v′v' works the same way, starting from the nose tip and offset by (−19.1,5.8)(-19.1, 5.8).

The rotation and scale of the whole face are handled by one global similarity transform, and local positions hang off the nearest landmark. If the current estimate is roughly right overall and only the left eye is off by 3 pixels, u′u' moves 3 pixels along with the left eye and still lands on "the patch above and to the right of the left eye." The similarity transform is the most expensive computation in this step; it's computed once per level and shared by all 500 trees.

How splits are chosen

Each node's candidate splits are generated at random. Draw two of this level's 400 pixels according to the prior (next section), give them a random threshold, repeat S=20S = 20 times, and keep the one with the smallest squared error. QQ is the set of samples that reach this node, and the split θ\theta divides them into a left and a right group, Qθ,lQ_{\theta,l} and Qθ,rQ_{\theta,r}:

E(Q,θ)=∑s∈{l,r} ∑i∈Qθ,s∥ri−μθ,s∥2E(Q, \theta) = \sum_{s\in\{l,r\}}\ \sum_{i\in Q_{\theta,s}} \left\| r_i - \mu_{\theta,s} \right\|^2

rir_i is the 388-dimensional residual of sample ii, and μθ,s\mu_{\theta,s} is the mean residual of that group, which is also the value the leaf stores. Every leaf stores a full 388-dimensional vector, so one tree's output moves all the points at once.

Twenty candidates, each needing the squared errors of two groups, sounds expensive. Expand the sum of squares for one group:

∑i∈Qs∥ri−μs∥2=∑i∈Qs∥ri∥2−∣Qs∣ μsTμs\sum_{i\in Q_s}\left\| r_i - \mu_s \right\|^2 = \sum_{i\in Q_s}\left\| r_i \right\|^2 - |Q_s|\,\mu_s^T\mu_s

Added over the left and right groups, the first term is the sum of squares of all residuals at the node, which doesn't depend on how they're split. So minimizing EE is the same as maximizing

∑s∈{l,r}∣Qθ,s∣ μθ,sTμθ,s\sum_{s\in\{l,r\}} |Q_{\theta,s}|\,\mu_{\theta,s}^T\mu_{\theta,s}

and only the left mean has to be computed. The right one can be backed out of the parent node's mean μ\mu:

μθ,r=∣Q∣ μ−∣Qθ,l∣ μθ,l∣Qθ,r∣\mu_{\theta,r} = \frac{|Q|\,\mu - |Q_{\theta,l}|\,\mu_{\theta,l}}{|Q_{\theta,r}|}

Reuse the four residuals from before, +5,+3,−3,−5+5, +3, -3, -5 (one dimension only). Candidate A puts the first two on the left, so the left mean is +4+4; the parent mean is 0, so the right mean =(4×0−2×4)/2=−4= (4\times0 - 2\times4)/2 = -4, and the score is 2×16+2×16=642\times16 + 2\times16 = 64. Candidate B puts +5,−3+5, -3 on the left, for a left mean of +1+1 and a right mean of −1-1, and scores only 4. The total sum of squares is 68, so the corresponding values of EE are 4 and 64, and A wins.

An exponential prior: nearby pixels are more useful

400 pixels make nearly 80,000 possible pixel pairs, and each node tries only 20 of them at random. Most will be two pixels half a face apart, and comparing their brightness says very little. The authors add an exponential prior to the sampling:

P(u,v)∝e−λ∥u−v∥P(u, v) \propto e^{-\lambda \left\| u - v \right\|}

The closer the pair, the more likely it is drawn. The paper uses λ=0.1\lambda = 0.1. Taking the probability at distance 0 as the baseline, distance 5 gives 0.61, distance 10 gives 0.37, and distance 30 only 0.05; a pixel pair 30 apart is about one-twelfth as likely to be drawn as one 5 apart. The paper doesn't state the unit of distance; from context, it's pixels in the mean face shape's coordinates.

Original Figure 4: two plots of pixel pairs in the mean face shape's coordinates, with blue dots for pixel positions and red lines joining the selected pairs. On the left, (a) the uniform prior: red lines span the whole face, many of them long lines from the forehead to the chin, like a tangled mess. On the right, (b) the exponential prior: the red lines are mostly short and cluster around the eyes, eyebrows, nose and mouth, faintly tracing the facial features.
Original Figure 4, Kazemi and Sullivan, from PDF page 6 of the CVPR 2014 open-access version, scholarly quotation.

Each red line is one selected pixel pair. The left plot uses uniform sampling, and long lines stretch from the forehead to the chin; the right one uses the exponential prior, and the segments get shorter and cluster around the facial features, so you can spot the eyes and the mouth at a glance. The paper notes that the feature pool is fixed at 20 in both plots.

What about points nobody labeled?

Large datasets often have missing annotations, such as the hidden half of a profile face. The authors give every point of every image a weight wi,j∈[0,1]w_{i,j}\in[0,1], where 0 means point jj of image ii is unlabeled and 1 means it's labeled (values in between can express annotation uncertainty). These go into a diagonal matrix Wi=diag(wi1,wi1,…,wip,wip)W_i = \mathrm{diag}(w_{i1}, w_{i1}, \dots, w_{ip}, w_{ip}), one entry each for the xx and the yy of every point.

Both the error and the leaf values become weighted versions:

E(Q,θ)=∑s∈{l,r} ∑i∈Qθ,s(ri−μθ,s)TWi (ri−μθ,s)μθ,s=(∑i∈Qθ,sWi)−1∑i∈Qθ,sWi ri\begin{aligned} &E(Q, \theta)\\ &\quad= \sum_{s\in\{l,r\}}\ \sum_{i\in Q_{\theta,s}} (r_i - \mu_{\theta,s})^T W_i\, (r_i - \mu_{\theta,s})\\[4pt] &\mu_{\theta,s}\\ &\quad= \Big(\sum_{i\in Q_{\theta,s}} W_i\Big)^{-1} \sum_{i\in Q_{\theta,s}} W_i\, r_i \end{aligned}

The gradient boosting residuals are multiplied by the weights as well, rik=Wi(ΔSi−fk−1)r_{ik} = W_i\big(\Delta S_i - f_{k-1}\big).

WiW_i is diagonal, so a leaf's mean is computed coordinate by coordinate. Suppose a leaf holds three samples, the xx residuals of some point are +2+2 and +4+4, and the third image doesn't label this point. The weighted mean is (2+4)/2=3(2+4)/2 = 3, counting only the two labeled samples. Forcing the unlabeled one in as 0 would give (2+4+0)/3=2(2+4+0)/3 = 2, dragged back by a number that doesn't exist.

A shape constraint without PCA

ASM and AAM restrict the shape to a PCA subspace so they don't estimate a face with its features out of place. ERT adds no shape constraint at all, and the authors point out that its output never leaves the linear subspace spanned by the training shapes in the first place.

The reason lies in the leaf values. Each leaf stores a mean of residuals ΔS=Sπi−S^\Delta S = S_{\pi_i} - \hat S, and the initial shapes are themselves training shapes (or their mean), so the residuals are differences of training shapes, and their means are still linear combinations of training shapes. Start from the mean face shape, add a few thousand such vectors, and the result is still a linear combination of training shapes. All 388 dimensions of the output move together, so a chin point can't run off to the forehead on its own.

Where one millisecond comes from

Unless stated otherwise, every experiment in the paper uses the same set of parameters:

SymbolMeaningValue
TTLevels10
KKTrees per level500
FFTree depth5
PPPixels sampled per level400
SSCandidate splits per node20
RRInitial shapes per image20
ν\nuLearning rate0.1
λ\lambdaPrior parameter0.1

Compiled from Section 3 of the paper.

At inference, each level first computes one similarity transform and reads 400 pixels, then runs 500 trees, each making 5 levels of comparisons and adding one 388-dimensional leaf vector. Over ten levels that comes to 4,000 pixel reads, 25,000 comparisons and 5,000 vector additions, about 1.94 million floating-point additions (this note's estimate). The paper gives the complexity as O(TKF)O(TKF), independent of image size; on a single CPU each image takes about one millisecond, and training on HELEN takes about an hour. The paper doesn't say which CPU.

The price is memory. A tree of depth 5 has 32 leaves, each storing 388 floats, so the leaves of 5,000 trees alone take about 250 million bytes (assuming float32). It's fast because everything is computed ahead of time and stored in tables; inference comes down to lookups and additions.

Discussion

Compared with what

The authors built two baselines of their own, with every parameter the same:

  • EF: the weak regressors are swapped for random ferns, features are picked at random, and regularization uses ESR's shrinkage. Fastest to train.
  • EF+CB: ferns plus correlation-based feature selection, which projects the residual onto a random direction ww and picks the pixel pair whose difference correlates most with wTriw^T r_i. This is the authors' reimplementation of ESR.

A number in parentheses after EF+CB means it was run from that many random initial shapes and the median was taken; everything without parentheses runs once from the mean face shape.

MethodHELENLFPW
STASM.111–
CompASM.091–
Belhumeur et al.–.040
ESR (original paper)–.034
EF.069.051
EF+CB.062.046
EF+CB (5).059.043
EF+CB (10).055.041
ERT.049.038

Compiled from Tables 1 and 2 of the paper; the numbers are mean errors normalized by the inter-ocular distance.

HELEN has 2,330 images, 2,000 for training and 330 for testing, and the authors consider it the hardest public dataset of the time. ERT run once gets .049, EF+CB run ten times with the median taken gets .055, and STASM and CompASM, two ASM variants, are above .09.

Take the LFPW column with a grain of salt. LFPW officially provides only image URLs, and many of them were dead by the time the paper was written, so the authors could download only 778 training images and 216 test images, not the same set earlier work used. The best number in the table is actually ESR's original .034, with ERT's .038 in second place. The authors' EF+CB couldn't reproduce ESR's number either, which they put down to the incomplete data. Later, the authors added a line on the project page saying that their own reimplementation of ESR gets about .043 on LFPW, well short of the original paper's .034.

Original Figure 3: two line charts with cascade levels 1 to 10 on the horizontal axis and mean error on the vertical axis. (a) HELEN: EF (orange) falls from about 0.123 to 0.067, EF+CB (solid red) to about 0.063, EF+CB (5) and EF+CB (10) (red dashed and dotted lines) to about 0.060 and 0.055, and ERT (green) starts at about 0.088, drops to 0.057 by level 3 and ends at 0.049, the lowest throughout. (b) LFPW: the same ordering, with ERT falling from about 0.066 to about 0.038.
Original Figure 3, Kazemi and Sullivan, from PDF page 6 of the CVPR 2014 open-access version, scholarly quotation.

This figure shows the mean error at the end of each level. The green line is ERT. It ends level 1 at around 0.088, about the same as level 1 of EF+CB run ten times, and by level 3 it is down to 0.057, already better than the .062 that a single EF+CB run reaches after all ten levels. When the conclusion says this framework reduces the error faster than previous work, this is the figure it means. For the same error, ERT uses an order of magnitude less computation, because EF+CB (10) runs the whole cascade ten times.

Ablations

The paper runs a series of ablations on HELEN, each changing one thing and keeping everything else at the default parameters.

  1. Prior. Uniform sampling .053, exponential prior .049.
  2. Regularization. No regularization .103, shrinkage (ν=0.1\nu = 0.1) .049, averaging .049. Averaging is a different approach, in which each step fits 10 trees and averages them (in effect a small random forest), with ν=1\nu = 1 and the same total number of trees. The two regularizers do equally well, and without regularization the error doubles. The authors' explanation is that every step of gradient boosting lowers the bias while raising the variance, and both approaches bring the variance back down. Averaging has the advantage that the 10 trees can be trained in parallel.
  3. Cascade. One level of 500 trees .085, one level of 5,000 trees .074, ten levels of 500 each .049. All three settings see the same total of 10×40010\times400 pixel points. With the same 5,000 trees, splitting them into ten levels that each resample pixels from the current estimate does far better than growing all 5,000 trees at once on one set of pixels. These numbers are the most direct evidence for shape-indexed features.

The two experiments on training data read more clearly in one table:

Images20 starts each40k samples total
100.090.062 (400 each)
200.074.057 (200 each)
500.059.054 (80 each)
1,000.054.052 (40 each)
2,000.049.049 (20 each)

Compiled from Tables 6 and 7 of the paper.

The middle column changes only the number of annotated images, with 20 initial shapes per image. The right column fixes "images × starts" at 40,000, giving each image more starts when there are fewer images. 100 images with 400 starts each get .062, much better than the .090 of the same 100 images with 20 starts, but still behind the .049 of 2,000 images. More starting points make up part of the gap, but they can't stand in for real annotated images. Then again, the middle column shows that past a few hundred images, adding more images brings slower and slower gains.

Here are the results with partial annotations. With 200 fully annotated images the error is .074. Adding 1,800 images with only 25% of their points labeled brings it to .067; with 50% of the points labeled, to .061; 2,000 fully annotated images give .049. Partially labeled images help, but they don't close the gap.

The authors point out the reason themselves. The positions of the 194 points are highly correlated, and the shape's real degrees of freedom are far fewer than 388. Equation (13) averages each coordinate separately, so an unlabeled point contributes no information at all, and there's no way to infer roughly where it is from the other points. In the conclusion, the authors also admit that the main components treat every dimension of the target as independent.

Limitations

The method starts from the mean face shape inside the face box, so where the box sits and how big it is directly determine the level-0 shape. If the box is placed differently from training, or the face is a large-angle profile and the mean face shape starts too far from the truth, the first few levels can't pull it back. Later methods for large poses simply brought a 3D face model into the picture.

The 300-W challenge of 2013 re-annotated LFPW, HELEN and AFW with one common set of 68 points and added 135 very hard iBUG images. The standard split is 3,148 training and 689 test images, and the test set is further divided into common (554 images, from LFPW and HELEN), challenging (the 135 iBUG images) and full (both combined). The authors posted an experiment close to 300-W on the project page, training on AFW plus the LFPW and HELEN training sets and testing on iBUG plus the LFPW and HELEN test sets; ERT gets .064, and SDM and ESR both get .075.

A few years later deep learning took over. In the 300-W table compiled in the Wing Loss paper, normalized by the inter-pupil distance, ERT scores 6.40% on full, against 7.58% for ESR and 7.52% for SDM in the same table, while a CNN trained with Wing Loss gets 4.04%.

How dlib implements it

The authors never released their own code. KTH's project page (still visible in the web archive) says "An implementation of the algorithm is available in dlib C++ library." So the ERT people use today is mostly Davis King's version.

Open shape_predictor_trainer.h and the default parameters are 10 cascade levels, 500 trees per level, a learning rate of 0.1, 20 starting points per image, a feature pool of 400, λ=0.1\lambda = 0.1 and 20 candidate splits per node, all matching the paper, except that the tree depth is 4 (the paper uses 5). They haven't changed from the 2014 version to today.

λ\lambda is defined the other way around. dlib's code uses accept_prob = exp(-dist/lambda), with distances measured in coordinates normalized to the face box, and the documentation specifically says "Note that this is the inverse of how it is defined in the Kazemi paper," adding that you should think of λ\lambda as "the fraction of the bounding box will we traverse to find a neighboring pixel." Turning λ\lambda up on the paper's intuition, to make pixel pairs more concentrated, does the opposite in dlib.

The initial shapes differ too. In dlib, 1 in every 20 samples starts from the mean face shape, and the rest start from a random weighted average of two or more randomly picked training shapes, rather than taking another face's shape directly as the paper does. For unlabeled points, dlib sets the target to the current estimate (a residual of 0) and divides the leaf value by the number of samples in which that point is labeled, which works out to exactly the 0/1 weighted mean of equation (13).

The inference code matches equation (7) one to one. Each level first uses find_tform_between_shapes to get the similarity transform from the current shape to the mean face shape, maps the 400 "nearest landmark plus offset" pixels back onto the image to read their grayscale values, then runs all 500 trees of that level and accumulates the leaf vectors onto the shape.

Where did the 68-point model come from? Davis King answered that in issue #359 (December 2016). It was trained on 300-W plus mirrored images, with parameters that were "essentially the default values." In the same thread, Davis King also warned that the face boxes must be placed the same way in training and testing. The dlib-models description puts it more bluntly. The 68-point model is designed for dlib's HOG detector, and with a detector whose boxes are aligned differently (including dlib's own CNN detector) it works worse. In another thread, issue #800 (September 2017), someone trained a predictor for the corners of ID cards on just a few photos with hand-drawn boxes, and the predicted points always drifted along with the box. e-fominov, who answered, pointed out that the box decides where and at what scale the shape predictor starts ("Rectangle defines the initial position and scale"), which is exactly the level-0 panel in the paper's figure.

The same description also raises a licensing issue. The 300-W license excludes commercial use, and one of the dataset's authors asked dlib to state that this model can't be used in commercial products; anyone who wants to should first ask a lawyer or Imperial College London.

In September 2017, dlib 19.7 added a 5-point model, trained on 7,198 faces that Davis King annotated, with points at the corners of both eyes and the bottom of the nose. The blog says it is only 8.8 MB, against 96 MB for the 68-point model, and that it works with both the HOG and the CNN detectors; it later became dlib's recommended model for aligning faces for recognition. These 5 points are defined differently from MTCNN's, which marks the two eye centers, the nose tip and the two mouth corners, so the two alignment templates can't be mixed.

The face_recognition package that many people start out with wraps dlib; face_landmarks uses the 68-point model by default and face_encodings the 5-point model. For a lot of people, that layer is how they end up using ERT.

Conclusion

ERT replaces each level of cascaded regression with 500 gradient-boosted regression trees, uses pixel differences that move with the current estimate as features, and adds an exponential prior so the trees favor nearby pixel pairs. On HELEN's 194 points, the error drops from .055 for EF+CB run ten times to .049 for a single run, and inference comes down to lookups and additions, about one millisecond per image. The strongest ablation is the cascade one, where the same 5,000 trees, split into ten levels that resample pixels, take the error from .074 down to .049.

If you're still using dlib's 68-point model, produce the face boxes with dlib's HOG detector, or retrain a model on your own detector's boxes. Once the box moves, the mean face shape at the start lands in the wrong place, and the ten levels of correction after it may not be able to rescue it. If it's going into a commercial product, sort out the 300-W license first.

The authors' own code was never released, and the paper now lives on in a .dat file in dlib.