Back to paper library
Paper notesarXiv 2019CVPR 2020

RetinaFace

Keeping a Straight Face

Original paper

RetinaFace: Single-stage Dense Face Localisation in the Wild

Paper authors

Jiankang Deng · Jia Guo · Yuxiang Zhou · Jinke Yu · Irene Kotsia · Stefanos Zafeiriou

Publication
CVPR 2020Conference
First submitted to arXiv
arXiv:1905.00641
Cite this paper · BibTeX

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

@misc{objectdetectionretinaface2019,
  title = {{RetinaFace: Single-stage Dense Face Localisation in the Wild}},
  author = {Jiankang Deng and Jia Guo and Yuxiang Zhou and Jinke Yu and Irene Kotsia and Stefanos Zafeiriou},
  year = {2019},
  eprint = {1905.00641},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1905.00641}
}
On this page
Original Figure 6: a crowd selfie taken on a plaza in front of a building, with a few young people in the foreground and a dense crowd behind them. Every detected face has a box colored from yellow to teal, the color giving its confidence score (color bar on the right, 0.5 to 1); inside each box, five green dots mark the two eyes, the nose tip and the two mouth corners, and a blue dense localization mask covers the face. Boxes in the foreground are large, while the distant ones are only a few pixels wide.
Original Figure 6, Deng et al., from PDF page 7, arXiv license, scholarly quotation.

This photo is said to be the world's largest selfie, with 1,151 people reported in the frame. At a confidence threshold of 0.5, RetinaFace finds about 900 faces, and besides its box, each face gets five points, on the two eyes, the nose tip and the two mouth corners. Faces in the front row are a few hundred pixels wide; in the last few rows they are down to a few pixels.

A face detector takes in a photo and spits out a list of face boxes, each with a confidence score. RetinaFace hands over five extra points, and those five points are meant for whatever comes downstream. A face-recognition model (ArcFace, for example) expects a straightened, cropped 112×112112\times112 face as input, and the straightening is done from exactly these five points. So the detector's quality carries all the way through to the answer to "are these two faces the same person?"

The paper comes from the InsightFace team, the same people who made ArcFace. First author Jiankang Deng is also the first author of ArcFace. The question they want to answer is a concrete one. If you add supervision for five points to a detector, does it get better at finding small faces?

Defining the Problem

Face detection can be seen as a special case of object detection with a single class, "face." Compared with generic objects, faces have a very stable aspect ratio, roughly 1:1 to 1:1.5, while their scale ranges from a few pixels to over a thousand.

The standard exam at the time was WIDER FACE. It has 32,203 images and 393,703 face boxes from 61 scene types (parades, sports meets, meetings, ...), split 4:1:5 into training, validation and test. Each subset is further divided by difficulty into Easy, Medium and Hard, according to whether a traditional proposal method (EdgeBox) can find the face; the harder a face is to find, the harder its group. The three groups are nested. Hard contains every face, many of them only a few pixels wide.

Scoring uses AP. A detection counts as correct if its IoU (intersection area divided by union area) with a labeled box exceeds 0.5. Sort all detections by score from high to low and go down the list; at each step compute precision (how many of the detections are real faces) and recall (how many of the real faces have been found), and plot them as a curve. AP is the area under that curve. When the paper was written, the best result on the Hard test set was 90.3% (ISRN).

Existing methods fell roughly into two camps. Two-stage methods (the Faster R-CNN line) first propose candidate boxes and then refine them, which localizes accurately but runs slowly. One-stage methods (the SSD and RetinaNet line) tile anchors over every position of the feature map and classify and regress directly. They are fast, but the vast majority of anchors are background, the positive/negative imbalance is extreme, and false positives are more common. SSH, S3FD and PyramidBox, the strong methods of the time, were all one-stage.

Detecting faces and landmarks together was not new. MTCNN chains three small networks into a cascade that filters stage by stage over an image pyramid, outputting boxes and five points at once; ArcFace originally used it for detection and alignment too. But such methods were limited by their training data, and nobody had verified whether five-point supervision actually helps detection on data like WIDER FACE, which is full of small faces.

The second question is bolder. Mask R-CNN showed that adding a branch that predicts pixel masks makes the detection itself better. Could faces get a "dense" branch too? The trouble is that the hard faces in WIDER FACE can't always be labeled even with five points, let alone per-pixel annotations.

Without labels, can the model supervise itself?

Solving the Problem

One 640×640 Image

Original Figure 2: on the left, a 640×640 crowd image overlaid with four ResNet feature maps C2 to C5, smaller toward the top; C5 goes through one more convolution to give C6/P6 (10×10×256). In the middle is the feature pyramid P2 to P5, with sizes 160×160×256, 80×80×256, 40×40×256 and 20×20×256, added level by level from top to bottom. On the right, a dashed box encloses the context module (×5): the 256-channel input splits into three paths of 128, 64 and 64 channels, which are concatenated back to 256 channels and fed to the multi-task loss at the far right.
Original Figure 2, Deng et al., from PDF page 4, arXiv license, scholarly quotation.

Let's follow one 640×640640\times640 training image through the network.

The backbone is ResNet-152, pretrained on ImageNet-11k. Its four stages C2 to C5 produce feature maps at 1/4, 1/8, 1/16 and 1/32 of the input. Following FPN, deeper features are upsampled and added to shallower ones to give P2 to P5; P6 comes from one more stride-2 3×33\times3 convolution on C5. The spatial sizes and strides of the five levels are:

LevelFeature mapStrideAnchor sides (px)
P2160×160×256416, 20.16, 25.40
P380×80×256832, 40.32, 50.80
P440×40×2561664, 80.63, 101.59
P520×20×25632128, 161.26, 203.19
P610×10×25664256, 322.54, 406.37

Compiled from Table 2 of the paper.

Each level gets its own context module, a design taken from SSH. The input has 256 channels. One path is a 3×33\times3 convolution (128 channels); the other first applies a 3×33\times3 convolution and then splits in two, one branch stacking one more 3×33\times3 and the other stacking two more 3×33\times3 (64 channels each). Two stacked 3×33\times3 layers have the receptive field of a 5×55\times5, and three stacked have that of a 7×77\times7. The three paths are concatenated back to 256 channels, so the same position sees both the face itself and the hair and shoulders around it.

Drawing on the experience of the WIDER Face Challenge 2018 winner, the authors also replace every 3×33\times3 convolution in the lateral connections and the context modules with deformable convolution (DCN). The winning entry's observation was that enlarging the receptive field (rigid context) and letting the sampling points follow deformation (non-rigid context) complement each other.

102,300 Anchors

Each position on each level holds 3 square anchors whose sides grow by a factor of 21/32^{1/3}, which is where the numbers in the table come from. P2 starts at 16, 16×21/3=20.1616\times2^{1/3}=20.16, and one more multiplication gives 25.40; P3 starts at 32, and so on. Together the five levels cover 16 to 406 pixels.

The count can be worked out too. P2 has 160×160×3=76,800160\times160\times3=76{,}800, P3 has 80×80×3=19,20080\times80\times3=19{,}200, and P4, P5 and P6 have 4,800, 1,200 and 300, for a total of 102,300, 75% of them on P2. To catch small faces, the authors put three quarters of the anchors on the finest level, at the price of more computation and more false positives.

The smallest anchor is 16 pixels, and that also decides how small a face can be learned. A 10×1010\times10 face sitting exactly at the center of a 16×1616\times16 anchor has an IoU of 100/256≈0.39100/256\approx0.39, short of the 0.5 threshold, so this face gets no positive sample during training. With concentric boxes, a face has to be at least about 11.3 pixels (16×0.516\times\sqrt{0.5}) to be matched.

Data augmentation during training deals with exactly this. About 20% of the WIDER FACE training set is small faces. The authors randomly crop a square from the original image with a side of 0.3 to 1 times the short side and resize it to 640×640640\times640. The smaller the crop, the more the faces inside are enlarged. For an original with a 1,000-pixel short side, cropping 300 pixels and enlarging to 640 makes the faces more than twice as big. A face cut by the crop boundary keeps its visible part as long as its center is still inside the crop. On top of that there is horizontal flipping with probability one half, and color distortion.

An anchor whose IoU with a labeled box exceeds 0.5 is a positive, one below 0.3 is background, and anything in between is ignored. After matching, over 99% are background, so the authors use OHEM to pick the hardest negatives by loss, keeping the ratio of negatives to positives at least 3:1.

Four Questions Every Anchor Answers

Original Figure 1: on the left, a crowd image and a feature map; one red position on the feature map pulls out four outputs in three groups. The first group, Existing branch: 2-dimensional face classification L_cls (a face versus a head of hair) and 4-dimensional face box regression L_box. The second group, Extra-supervision: 10-dimensional five-point landmark regression L_pts. The third group, Self-supervision: a 128+7+9-dimensional output split into shape and texture parameters P_ST, camera parameters P_cam and illumination parameters P_ill; P_ST passes through a series of mesh graph convolutions, from coarse to dense, to become a colored 3D face, which goes to a differentiable 3D mesh renderer, and the rendered face is subtracted from the face in the original image, labeled Dense face regression, with the loss L_pixel.
Original Figure 1, Deng et al., from PDF page 1, arXiv license, scholarly quotation.

The context modules are followed by an output head of 1×11\times1 convolutions, shared by all five levels. For each anchor ii, the paper minimizes this multi-task loss:

L=Lcls(pi,pi∗)+λ1pi∗Lbox(ti,ti∗)+λ2pi∗Lpts(li,li∗)+λ3pi∗Lpixel\begin{aligned} L={}&L_{cls}(p_i, p_i^*)+\lambda_1 p_i^* L_{box}(t_i, t_i^*)\\ &+\lambda_2 p_i^* L_{pts}(l_i, l_i^*)+\lambda_3 p_i^* L_{pixel} \end{aligned}

pip_i is the model's probability that anchor ii is a face, and pi∗p_i^* is the label, 1 for positives and 0 for background. The last three terms are all multiplied by pi∗p_i^*, so background anchors only contribute the classification loss; only positives have to answer where the box is, where the five points are and what the face looks like.

The number of output channels per anchor is written on the left of Figure 1. Classification has 2 (face or not, with a two-class softmax), the box 4, the five points 10, and the self-supervised branch 128+7+9=144128+7+9=144.

Let's run the numbers for one concrete anchor. Suppose P3 has a 32×3232\times32 anchor centered at (96,96)(96, 96), covering x,y∈[80,112]x, y \in [80, 112]. Nearby is a labeled face whose box is x∈[86,114]x\in[86,114], y∈[84,120]y\in[84,120], 28 wide and 36 tall, centered at (100,102)(100, 102).

The intersection of the two boxes is 26×28=72826\times28=728 and the union is 1024+1008−728=13041024+1008-728=1304, so the IoU is about 0.56. That is above 0.5, so this anchor is a positive.

The box regression targets follow Fast R-CNN, with center offsets divided by the anchor side and log ratios for width and height:

tx∗=100−9632=0.125ty∗=102−9632=0.1875tw∗=ln⁡2832≈−0.134th∗=ln⁡3632≈0.118\begin{aligned} t_x^* &= \frac{100-96}{32} = 0.125\\ t_y^* &= \frac{102-96}{32} = 0.1875\\ t_w^* &= \ln\frac{28}{32} \approx -0.134\\ t_h^* &= \ln\frac{36}{32} \approx 0.118 \end{aligned}

The model outputs tit_i, and LboxL_{box} is the smooth-L1 of each dimension of ti−ti∗t_i - t_i^*. Smooth-L1 is 0.5x20.5x^2 when the absolute error is below 1 and ∣x∣−0.5|x|-0.5 above 1, so large errors don't blow up the way squared error does.

The five-point regression targets are normalized with the same anchor center. Suppose the left eye is at (93,96)(93, 96) and the nose tip at (100,104)(100, 104); the targets are

(93−9632,96−9632)=(−0.094, 0)(100−9632,104−9632)=(0.125, 0.25)\begin{aligned} \left(\frac{93-96}{32}, \frac{96-96}{32}\right) &= (-0.094,\ 0)\\ \left(\frac{100-96}{32}, \frac{104-96}{32}\right) &= (0.125,\ 0.25) \end{aligned}

The five points make 10 numbers, and LptsL_{pts} is again smooth-L1. The official code computes exactly this, the point coordinate minus the anchor center, divided by the anchor's width or height.

The three weights are λ1=0.25\lambda_1=0.25, λ2=0.1\lambda_2=0.1 and λ3=0.01\lambda_3=0.01. The authors' reasoning is that the supervised box and five points are more reliable signals and therefore weigh more, while the self-supervised pixel loss takes only a small share.

Where the Five Points Come From

WIDER FACE originally had only boxes. The authors first sorted the faces into five levels by how hard their landmarks are to annotate, then added five points to the faces that could be annotated:

LevelFacesCriterion
14,127indisputable 68 landmarks
212,636annotatable 68 landmarks
338,140indisputable 5 landmarks
450,024annotatable 5 landmarks
594,095recognizable only by context

Compiled from Table 1 of the paper. "Indisputable" means an annotator can locate the landmarks without much effort; "annotatable" means finding an approximate location takes some effort.

In the end, 84.6k faces were annotated in the training set and 18.5k in the validation set, with five points: the two eye centers, the nose tip and the two mouth corners. These annotations were later released along with the code, and both the community PyTorch reimplementation and the same team's later SCRFD train on them.

A Dense Branch Without Labels

The fourth term, LpixelL_{pixel}, is the flashiest part of the paper. The goal is for every positive anchor to reconstruct a colored 3D face, render it back to 2D and compare it with the face in the original image.

The authors take the mesh decoder of Zhou et al., from the same lab, as is. A face is represented as a mesh graph G=(V,E)\mathcal G=(\mathcal V,\mathcal E), where V∈Rn×6\mathcal V\in\mathbb R^{n\times6} holds nn vertices, each storing 3 coordinates and 3 color values, and E∈{0,1}n×n\mathcal E\in\{0,1\}^{n\times n} is the adjacency matrix, 1 where two vertices are joined by an edge.

To convolve on a mesh, you first have to define "neighbors." For a 3×33\times3 convolution on an image, the neighbors are the eight surrounding cells. A mesh has no up, down, left or right, so how far a neighbor is gets measured by the minimum number of edges you have to walk.

Graph convolution uses the graph Laplacian L=D−EL = D - \mathcal E, where DD is a diagonal matrix and DiiD_{ii} is the number of edges leaving vertex ii. Multiplying LL by a signal xx on the vertices gives, at vertex ii,

(Lx)i=Dii xi−∑j∈N(i)xj(Lx)_i = D_{ii}\,x_i - \sum_{j\in\mathcal N(i)} x_j

In words, "yourself times the number of neighbors, minus the values of all your neighbors." For example, if vertex ii has three neighbors with values 0.5, 0.2 and 0.3 and its own value is 1, then (Lx)i=3×1−(0.5+0.2+0.3)=2(Lx)_i = 3\times1-(0.5+0.2+0.3)=2. One multiplication by LL only reaches neighbors within one step; two multiplications reach those within two steps.

The filter is written as a polynomial in the Laplacian, and the coefficients are the learned parameters. The paper uses a Chebyshev polynomial expansion truncated at order KK:

y=gθ(L) x=∑k=0K−1θk Tk(L~) xy = g_\theta(L)\,x = \sum_{k=0}^{K-1}\theta_k\, T_k(\tilde L)\,x

L~\tilde L is the scaled Laplacian, whose eigenvalues lie in [−1,1][-1,1] (ChebNet defines it as L~=2L/λmax−I\tilde L = 2L/\lambda_{max} - I). TkT_k satisfies the recurrence Tk=2L~ Tk−1−Tk−2T_k = 2\tilde L\,T_{k-1} - T_{k-2}, so the matrices never have to be computed explicitly. Start from xˉ0=x\bar x_0 = x and xˉ1=L~x\bar x_1 = \tilde L x and repeat

xˉk=2L~ xˉk−1−xˉk−2\bar x_k = 2\tilde L\,\bar x_{k-1} - \bar x_{k-2}

L~\tilde L is very sparse, so each step is just one sparse matrix–vector product. Finally y=[xˉ0,…,xˉK−1] θy = [\bar x_0,\dots,\bar x_{K-1}]\,\theta takes a weighted sum of the KK results. TkT_{k} is a degree-kk polynomial in L~\tilde L, so a KK-term filter only sees neighbors within K−1K-1 steps, playing the same role as a finite-size kernel in image convolution. The parameter counts line up as well: a 3×33\times3 convolution layer has 3×3×Cin×Cout3\times3\times C_{in}\times C_{out} parameters, and a graph convolution layer has K×Cin×CoutK\times C_{in}\times C_{out}.

In the full dense branch, the 144-dimensional output of a positive anchor is split into three parts:

  1. PST∈R128P_{ST}\in\mathbb R^{128}, a latent vector for shape and texture. The mesh decoder unfolds it into a colored 3D face through a series of graph convolutions and mesh upsampling. The decoder loads pretrained weights directly.
  2. PcamP_{cam}, 7 camera parameters (3 for position, 3 for pose, 1 for focal length).
  3. PillP_{ill}, 9 illumination parameters (3 for the point light's position, 3 for its color, 3 for the ambient light's color).

A differentiable 3D mesh renderer uses the camera and lighting to draw this 3D face as a 2D image I^=R(DPST,Pcam,Pill)\hat I=\mathcal R(\mathcal D_{P_{ST}}, P_{cam}, P_{ill}), which is compared pixel by pixel with the crop I∗I^* of the original image for this anchor:

Lpixel=1WH∑i=1W∑j=1H∥I^i,j−Ii,j∗∥1L_{pixel} = \frac{1}{W H}\sum_{i=1}^{W}\sum_{j=1}^{H}\left\| \hat I_{i,j} - I^*_{i,j} \right\|_1

WW and HH are the crop's width and height. The answer key is the original image itself, with no 3D labels needed, which is why the branch is called "self-supervised." The renderer is differentiable, so the error can flow all the way back to the 144-dimensional output and on into the backbone.

The authors themselves point out two concerns in the introduction. First, camera parameters are hard to estimate accurately. Second, the original mesh decoder took face features cropped by RoI pooling, whereas here a single 1×1×2561\times1\times256 vector at one position of the feature pyramid has to predict an entire 3D face, and the feature and the face may not line up.

Training and Testing Setup

Training uses SGD with momentum 0.9 and weight decay 0.0005, on four Tesla P40s with 8 images each. The learning rate starts at 10−310^{-3}, rises to 10−210^{-2} after 5 epochs, is divided by 10 at epochs 55 and 68, and training ends at epoch 80.

Testing on WIDER FACE follows the convention of the time. The short side is resized to five scales, 500, 800, 1100, 1400 and 1700, each also horizontally flipped, and all detections are merged with box voting (IoU 0.4). All the WIDER FACE results below use this setting.

Discussion

Ablation: the Five Points Help, the Dense Branch Is Hard to Call

SettingEasyMediumHardmAP
FPN + context95.53295.13490.71450.842
+ DCN96.34995.83391.28651.522
+ LptsL_{pts}96.46796.07591.69452.297
+ LpixelL_{pixel}96.41395.86491.27651.492
+ LptsL_{pts} + LpixelL_{pixel}96.94296.17591.85752.318

Compiled from Table 3 of the paper, WIDER FACE validation set, ResNet-152.

The first three columns are AP at IoU 0.5. The last column, mAP, comes from the WIDER Face Challenge 2018 evaluation server (Hard validation subset), which computes AP with the IoU threshold raised from 0.5 to 0.95 in steps of 0.05 and averages the results, so the more precisely the boxes are drawn, the higher the score.

There are three things to read in this table.

  1. The baseline is already strong. FPN, the context module and DCN already reach 91.286 on Hard, above the 90.9 that ISRN, the best method at the time, scored on the validation set. The final 91.857 is 0.957 above ISRN, and 0.386 of that was there before the five points were added.
  2. The five points clearly help. Adding five-point supervision raises Hard AP by 0.408 and mAP by 0.775. The stricter mAP rises more, which looks more like tighter boxes than just a few more faces found.
  3. The dense branch alone does nothing. Adding only LpixelL_{pixel} nudges Easy and Medium up, moves Hard from 91.286 down to 91.276, and also lowers mAP slightly. Used together with the five points, it adds 0.163 Hard AP and 0.021 mAP over the five points alone. The authors read this as "landmark regression does help dense regression, which in turn boosts face detection performance even further." Each cell in the table is a single number with no standard deviation, so whether a 0.02 mAP gap can be told apart from training noise is something this table can't answer.

WIDER FACE Results

Against 24 methods, RetinaFace reaches 96.9/96.1/91.8 (Easy/Medium/Hard) on the validation set and 96.3/95.6/91.4 on the test set. Test Hard is 1.1 percentage points above ISRN's 90.3, which is the number in the abstract.

The selfie at the top is also this section's qualitative result. The paper says the five points hold up well under changes in pose, occlusion and resolution; the blue dense mask shows facial expressions on clear, large faces and fails under heavy occlusion.

How Accurate Are the Five Points and the 3D?

The five points were also benchmarked on their own. On AFLW (24,386 faces), the mean error normalized by the box size W×H\sqrt{W\times H} (NME) is 2.72% for MTCNN and 2.21% for RetinaFace. On the 18.5k faces of the WIDER FACE validation set, counting an NME above 10% as a failure, MTCNN fails 26.31% of the time and RetinaFace 9.37%.

The dense branch's results are less flattering. On AFLW2000-3D, evaluating the 2D projections of 68 points, the NMEs are PRNet 3.27, 3D-FAN 3.48, Mesh Decoder 3.99, DeFA 4.37 and 3DDFA 6.03, against RetinaFace's 7.17 (with five-point supervision) and 8.53 (without). The comparison over all 3D points is the same, with RetinaFace in last place. The paper describes these results as "comparable" with those methods (dead last also counts as comparable); a more honest description is that it falls well short, with PRNet's error less than half of RetinaFace's.

The authors' own analysis is spot on, though. Predicting dense correspondence from single-stage 1×1×2561\times1\times256 features is far harder than from RoI features, and misaligned, over-compacted features are the main reason; five-point supervision eases the training of the dense branch (7.17 vs 8.53).

ArcFace After Replacing MTCNN

This experiment shows the value of the five points best. ArcFace originally used MTCNN for detection and alignment. The authors re-detected and re-aligned the MS1M training data and every test set with RetinaFace, leaving the embedding network (ResNet100) and the additive angular margin loss completely unchanged.

The alignment can be seen in InsightFace's code. The 112×112112\times112 output image has a fixed five-point template: the left eye at about (38.3,51.7)(38.3, 51.7), the right eye at about (73.5,51.5)(73.5, 51.5), the nose tip at about (56.0,71.7)(56.0, 71.7), and the two mouth corners at about (41.5,92.4)(41.5, 92.4) and (70.7,92.2)(70.7, 92.2). A similarity transform (rotation, uniform scaling, translation) between the detector's five points and this template is estimated by least squares, and the face is straightened and cropped. If the five points are off, the whole face ends up crooked.

Face verification (1:1) decides whether two faces belong to the same person. LFW, CFP-FP and AgeDB-30 report verification accuracy:

Detect & alignLFWCFP-FPAgeDB-30
MTCNN99.8398.3798.15
RetinaFace99.8699.4998.60

Compiled from Table 4 of the paper.

The biggest change is on CFP-FP, which pairs frontal and profile faces of the same person. Switching to RetinaFace raises it from 98.37 to 99.49, bringing frontal-versus-profile close to LFW's frontal-versus-frontal.

The IJB-C numbers need some explanation before they can be read. TAR@FAR=1e-6 means first setting the decision threshold so that only one pair in a million "different people" pairs gets falsely accepted, then checking what fraction of "same person" pairs that threshold accepts. IJB-C compares templates, and one person's template can hold several photos and video frames. At this strict threshold:

  • with no tricks on either side, MTCNN gets 86.25% and RetinaFace 88.73%;
  • with flip testing (+F), 86.41% vs 89.12%;
  • with detection scores also weighting the photos within a template (+S), 88.29% vs 89.59%.

The abstract quotes the last pair, a gap of 1.30 percentage points, which works out to about 130 more same-person pairs accepted per ten thousand. Without tricks the gap is actually larger, 2.48 percentage points. Weighting by detection score lowers the weight of low-scoring frames such as blurry or profile shots, and that trick wins back a good deal for MTCNN.

Speed

Besides ResNet-152 (262MB, 91.8% on validation Hard), the authors also built a lightweight MobileNet-0.25 version (1MB, Hard 78.2%). To save computation, the lightweight version changes four things. The input is shrunk right away by a stride-4 7×77\times7 convolution, anchors are tiled only on P3 to P5, deformable convolution is removed, and the first two convolution layers pretrained on ImageNet are frozen.

Model (platform)VGAHD4K
ResNet-152 (GPU)75.1443.21742
MobileNet-0.25 (GPU)1.46.125.6
MobileNet-0.25 (CPU, multi-thread)5.550.3–
MobileNet-0.25 (CPU, single thread)17.2130.4–
MobileNet-0.25 (ARM)61.2434.3–

Compiled from Table 5 of the paper, in milliseconds. VGA is 640×480, HD is 1920×1080 and 4K is 4096×2160; the GPU is a Tesla P40, the CPU an i7-6700K and the ARM chip an RK3399.

The abstract's claim that RetinaFace "can run real-time on a single CPU core for a VGA-resolution image" corresponds to the 17.2 ms, about 60 images per second. These timings were sped up with TVM compilation and leave out the dense branch; they count only the network's forward pass. A user reported in issue #1028 (December 2019) that the official Python package takes 80 ms for a 1080p image on an RTX 2080 Ti, and the reply pointed out that the paper's numbers exclude pre- and post-processing. Estimating end-to-end pipeline latency straight from this table will come out too optimistic.

The CVPR 2020 Version: Everything Becomes Points

The published version is titled RetinaFace: Single-shot Multi-level Face Localisation in the Wild, with dense swapped for multi-level. The content was heavily rewritten too, and the dense branch was replaced entirely.

The new version starts from the observation that detection, five-point alignment and 3D reconstruction all predict "points on the image," just different numbers of them. A box can be seen as two corners, five landmarks are five points, and a 3D face is a set of vertices with fixed topology projected onto the image, plus a depth zz. Since they are all points, they all get the same kind of regression target.

Figure 2 of the CVPR 2020 version: (a) Network Structure: on the left, the same ResNet and feature pyramid P2 to P6; on the right, the context module has become two cascaded heads, one above the other, feeding Multi-task Loss 1 and Multi-task Loss 2, labeled Cascade Multi-scale Context Head Module (5 scales, 2-stage cascade). (b) Multi-task Loss: a w×h×256 feature map pulls out four outputs, 2-dimensional classification, 4-dimensional box regression, 10-dimensional five-point regression and 1k×3-dimensional 3D vertex regression L_mesh, next to a face overlaid with 1k vertices and a gray rendered 3D mesh.
Figure 2 of the CVPR 2020 version, Deng et al., from PDF page 4 of that version, scholarly quotation.

Regressing 3D vertices requires 3D labels, so the new version builds a semi-automatic pipeline. For each face, 68 3D landmarks are found automatically and used to drive a 3DMM (3D morphable face model) fit, which reconstructs a 3D face with 53K vertices and projects it onto the image plane. To check the fit, the system recovers a UV texture map from the fitted result for annotators to inspect; if it is flawed, the 68 points are corrected by hand and the fit is redone, and if it still fails, the face is discarded. In the end 22k faces in the WIDER FACE training set were kept, plus 27.1k on AFLW and 39.3k on FDDB.

The vertices actually regressed are a subset of the 53,215 vertices, in two groups. Mesh68 is 68 vertices with 111 triangles, used for quantitative evaluation; Mesh1k is 1,035 vertices with 1,999 triangles, keeping facial detail. Both groups are regressed together, for N=1103N=1103 vertices and M=2110M=2110 triangles in total.

The vertex loss is the point-wise L1 distance between prediction and label:

Lvert=1N∑i=1N∥Vi(x,y,z)−Vi∗(x,y,z)∥1L_{vert} = \frac{1}{N}\sum_{i=1}^{N}\left\| V_i(x,y,z) - V_i^*(x,y,z)\right\|_1

The x,yx, y of visible vertices can be learned directly from the image, but zz and occluded vertices are much harder. The authors borrow the mesh topology and add an edge-length loss. Each triangle has three edges, and the predicted edge lengths EiE_i are compared with the labeled ones Ei∗E_i^*:

Ledge=13M∑i=1M∥Ei−Ei∗∥1L_{edge} = \frac{1}{3M}\sum_{i=1}^{M}\left\| E_i - E_i^*\right\|_1

Lmesh=Lvert+λ0LedgeL_{mesh} = L_{vert} + \lambda_0 L_{edge}, with λ0=1\lambda_0 = 1. The edge-length constraint keeps the mesh from twisting freely, and neighboring vertices hold each other's depth in check.

The regression targets are unified too. Box width and height are still log ratios, log⁡(w∗/sa)\log(w^*/s_a) and log⁡(h∗/sa)\log(h^*/s_a), where sas_a is the anchor scale. The box's two corners, the five points and the 1k vertices are all written as

xj∗−xcenterasa,yj∗−ycenterasazj∗−znose∗sa\begin{aligned} &\frac{x_j^* - x^a_{center}}{s_a},\quad \frac{y_j^* - y^a_{center}}{s_a}\\ &\frac{z_j^* - z^*_{nose}}{s_a} \end{aligned}

The first two are exactly what we computed earlier for the left eye and the nose tip, and even the anchors carry over. zz is first shifted so the nose tip sits at 0, then divided by the anchor scale. All regressions use smooth-L1, and the three weights λ1\lambda_1 to λ3\lambda_3 are all set to 1, because the three tasks are now the same kind of problem.

The other architectural change is cascade regression. The context module becomes two cascaded heads. The first head predicts boxes from the original anchors, and the second starts from the boxes regressed by the first and predicts more precisely. The two heads use different matching thresholds. For the first, IoU above 0.7 is a positive and below 0.3 is background; the second uses 0.5 and 0.4.

The new version's ablation uses ResNet-50; the last column is the average AP over IoU 0.5 to 0.95 on the Hard test subset:

SettingHard (val)Avg AP (test)
Baseline89.87552.65
+ DCN90.28653.36
+ cascade90.64254.20
+ LptsL_{pts}91.16154.73
+ LvertL_{vert}90.98354.55
+ LmeshL_{mesh}90.99154.62
+ LptsL_{pts} + LmeshL_{mesh}91.44755.02

Compiled from Table 1 of the CVPR 2020 version, ResNet-50. Every + LL row builds on "+ cascade."

In test-set average AP, the five points add 0.53, the 1k vertices 0.35, and the two together 0.82. The authors explain that five points are easy to label and plentiful, whereas 3D vertices exist for only 22k faces. The edge-length constraint helps detection very little but is useful for the zz coordinate and pose estimation. Compared with the arXiv version's pixel loss, which lowered the score when added, supervised vertex regression is at least positive on every term.

The new version makes one more observation. The baseline model gives scores above 0.9 to some non-face regions, and with five-point and 3D vertex supervision added, those regions drop below 0.3. The authors explain that five points are labeled only on faces where they are "annotatable," and 3D vertices only on easy to medium faces, so these labels quietly tell the model how much information a face carries, and the model learns to give high scores only to information-rich faces.

The ResNet-152 version reaches 91.7% on WIDER FACE test Hard. The 3D side turned around as well. On the AFLW2000-3D 68-point evaluation grouped by yaw angle, five points plus the mesh loss reach an NME of 3.48%, below PRN's 3.62% and MS-SFN's 3.89%. The two versions compute their 3D evaluations differently, so the numbers can't be subtracted directly; but the arXiv version ranked last and the CVPR version ranks first. What changed in between is the supervision. One version renders back and compares against the original image itself, the other has 3D labels for 22k faces.

The author list changed too. Yuxiang Zhou and Jinke Yu from the arXiv version moved to the acknowledgments, which state that Zhou contributed the graph-convolution mesh decoder and Yu did the experiments on mobile devices. The whole graph-convolution section no longer exists in the published version.

Official Code and Community Implementations

The official code lives in InsightFace's detection/retinaface, written in MXNet. Open it up and there are several gaps from the paper.

The first is the models. The README provides a ResNet-50 version, 96.5/95.6/90.4 on the WIDER FACE validation set with multi-scale testing; a MobileNet-0.25 version, trained by community user yangfly, gets 82.5 on Hard. For the paper's best ResNet-152 model, the README says "To avoid the confliction with the WiderFace Challenge (ICCV 2019), we postpone the release time of our best model." Issue #847 asked about it in August 2019, after the challenge had ended, and the follow-ups went on for over a year. Maintainer nttstar replied in September 2020 that "The best challenge model has many tricks and is not easy enough to be published," and added that "The biggest model is not production-grade." Someone else in the same thread said they could not reproduce the selfie on the project page with R50 no matter what they tried. The issue was closed in June 2023, and the README's "postpone" sentence is still there today (quite the postponement).

The second is the dense branch. The training code has a line if config.USE_3D: from rcnn.PY_OP import rpn_3d_mesh followed by a pass, and the rpn_3d_mesh module is not in the repo. As early as May 2019, someone asked in issue #687 where the Dense Regression Loss was, and author Jiankang Deng replied that the best model, dense branch included, would be released later because the team was entering the challenge. The follow-ups ran all the way into 2021; this issue was also closed in June 2023, and the module never showed up.

The third is the default settings. In the sample config, the ResNet block first writes out the paper's settings (ResNet-152, deformable convolution, three anchors per level on P2 to P6). The end of the file then switches to ResNet-50, turns deformable convolution off, and replaces the anchors with SSH-style three levels (strides 8, 16, 32), two sizes per level: 16 and 32, 64 and 128, 256 and 512. The landmark loss coefficient is also multiplied by an extra LANDMARK_LR_MULT (default 2.0), which puts the landmark weight relative to the box at twice the paper's λ2/λ1\lambda_2/\lambda_1.

The most widely used community version is biubug6/Pytorch_Retinaface, with about three thousand stars, offering MobileNet-0.25 and ResNet-50 backbones. It also goes with three anchor levels, no deformable convolution and no dense branch; its loss is "2 × box loss + classification loss + landmark loss," with a positive threshold of 0.35 and a negative-to-positive ratio of 7:1, all different from the paper. Its README lists single-scale ResNet-50 validation results of 94.82/93.84/89.60, against 94.86/93.87/88.33 for the official MXNet model in the same table, so the two are close. Its training data is exactly the officially released five-point annotations.

Another common entry point is serengil/retinaface, whose README states that the model structure and pretrained weights are the same as the official ones; it is also one of the detection backends of the deepface library.

So the RetinaFace people talk about today is mostly the ResNet-50 or MobileNet-0.25 model with "FPN plus SSH context modules, outputting boxes and five points." The dense in the paper's title is nowhere to be found in the public code and weights.

Conclusion

RetinaFace builds a very strong one-stage baseline from FPN, SSH-style context modules and deformable convolution, then adds hand-annotated five points to reach 91.4% on the WIDER FACE Hard test set. The contribution of the five points is clear in the ablation, and once they are handed to ArcFace for alignment, profile-face verification and IJB-C improve along with them. The self-supervised dense branch doesn't help when added alone, and the published version replaced it with labeled 3D vertex regression.

Before putting RetinaFace in front of face recognition, check two things. First, the order and definition of the detector's five points (eye centers, nose tip, two mouth corners) must match the alignment template the recognition model was trained with; if the point definitions differ, the similarity transform sets the face crooked and the recognition scores drop straight away. Second, the paper's WIDER FACE results come from five scales plus flipping. Two years later, the same team retested the official ResNet-50 version at a single 640-pixel scale in the SCRFD paper, and Hard was down to 64.17. If the faces in your frames are small, raise the input resolution first.

InsightFace's Python package later switched its default detector from retinaface_r50_v1 to SCRFD. That selfie of more than a thousand people still hangs at the top of the face-detection README, and the model that drew it is still postponed.