Back to paper library
Paper notesarXiv 2022ICIP 2022

6DRepNet

Six for a Smooth Ride

Original paper

6D Rotation Representation For Unconstrained Head Pose Estimation

Paper authors

Thorsten Hempel · Ahmed A. Abdelrahman · Ayoub Al-Hamadi

Publication
ICIP 2022Conference
First submitted to arXiv
arXiv:2202.12555
Cite this paper · BibTeX

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

@misc{faceanalysis6drepnet2022,
  title = {{6D Rotation Representation For Unconstrained Head Pose Estimation}},
  author = {Thorsten Hempel and Ahmed A. Abdelrahman and Ayoub Al-Hamadi},
  year = {2022},
  eprint = {2202.12555},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2202.12555}
}
On this page

Turn a head into full profile, yaw 90°. At that point, a head with pitch 30° and roll 10° and a head with pitch 20° and roll 0° give exactly the same rotation matrix; so does pitch 40° with roll 20°.

The same profile photo can be labeled with Euler angles (30°,90°,10°)(30°, 90°, 10°), or (20°,90°,0°)(20°, 90°, 0°), or infinitely many others. Use Euler angles as the regression target, and the network has to memorize several answers for the same face.

This is the problem Thorsten Hempel, Ahmed A. Abdelrahman and Ayoub Al-Hamadi of the Neuro-Information Technology group at Otto von Guericke University Magdeburg in Germany set out to handle. The authors switch the labels from Euler angles to rotation matrices; the network outputs only 6 numbers, which Gram–Schmidt orthogonalization turns back into a 3×33\times3 rotation matrix, and the loss is the geodesic distance between two rotations. The 6D in the name is these 6 numbers.

Defining the Problem

Where Euler Angles Get Stuck

Head pose is usually described with three Euler angles. Yaw is turning the head left and right, with 0° facing forward and ±90° a full profile; pitch is nodding up and down; roll is tilting the head toward a shoulder. The three angles must be applied in a fixed order. 6DRepNet's code uses R=Rz(roll) Ry(yaw) Rx(pitch)R=R_z(\text{roll})\,R_y(\text{yaw})\,R_x(\text{pitch}): pitch first, then yaw, and roll last, so yaw is the middle turn.

When the middle turn reaches ±90°, the axes of the first and third turns land on top of each other; this is gimbal lock. Plug in yaw = 90°, write pitch as pp and roll as rr, and multiplying out gives

R=[0sin⁡(p−r)cos⁡(p−r)0cos⁡(p−r)−sin⁡(p−r)−100]R=\begin{bmatrix}0&\sin(p-r)&\cos(p-r)\\0&\cos(p-r)&-\sin(p-r)\\-1&0&0\end{bmatrix}

Only p−rp-r remains in the matrix. Pitch turns first, then yaw turns 90°, which carries the pitch axis onto the same line as the roll axis, pointing the opposite way, so only the difference between the two angles means anything. (30°,10°)(30°, 10°), (20°,0°)(20°, 0°) and (40°,20°)(40°, 20°) all differ by 20°, so they're the same pose; that's where the three labels at the start come from. For head pose, yaw ±90° is simply a profile face, not some rare corner case.

The second trap comes after crossing over. Convert a rotation matrix back to Euler angles with the official code's formula, and yaw only ranges from −90° to 90°. Turn the head a little further, and the conversion makes pitch and roll each jump to 180° while yaw heads back. A head with a true yaw of 95° comes out at around (pitch,yaw,roll)=(180°,85°,180°)(\text{pitch}, \text{yaw}, \text{roll})=(180°, 85°, 180°).

Three line charts drawn for this note, stacked vertically. The horizontal axis of each is the angle θ the head actually turns about the vertical axis, from 0° to 360°, labeled below as front, profile, back of head, profile, front; 0° to 99° and 261° to 360° are shaded light blue, the range kept in AFLW2000 and BIWI evaluation. The top chart is Euler angles: blue yaw rises from 0 to 90°, falls all the way to −90° and comes back to 0, like a zigzag; orange pitch and roll jump from 0 to 180° at θ = 90° and jump back to 0 at 270°. The middle chart is the quaternion restricted to w ≥ 0: gray w falls from 1 to 0 and rises back to 1, while the purple y component rises from 0 to 1, jumps straight to −1 at 180° and rises back to 0. The bottom chart is the first column of the 6D representation: the green x component is a cosine curve and the blue z component a negative sine curve, both smooth, with no jumps at all.
Drawn for this note from the argument in Section 2 of the paper and the conversion formula in the official code.

This figure turns a head a full circle about the vertical axis and tracks how the labels from three representations change.

The top chart is Euler angles. At 90° (profile), the orange line jumps from 0 to 180° in one go, and the blue yaw starts heading back. The real poses differ by a hair, yet the labels differ by 180°. The light blue is the ∣yaw∣≤99°|\text{yaw}|\le99° kept in AFLW2000 and BIWI evaluation, and the small stretch from 90° to 99° is already on the far side of the jump.

The middle chart is the quaternion. A rotation can be written as 4 numbers (w,x,y,z)(w, x, y, z); turning θ\theta about a unit axis n\mathbf n is (cos⁡θ2, nsin⁡θ2)(\cos\frac\theta2,\ \mathbf n\sin\frac\theta2). Quaternions have no gimbal lock, but qq and −q-q represent the same rotation. The usual way to give each rotation a single label is to require w≥0w\ge0, at the cost of the purple line jumping from 1 to −1 at 180° (the back of the head facing the camera). A head turned 170° is labeled (0.087,0,0.996,0)(0.087, 0, 0.996, 0) and one turned 190° is labeled (0.087,0,−0.996,0)(0.087, 0, -0.996, 0), though the two poses are only 20° apart.

Zhou et al.'s 2019 paper proved that this isn't any one representation's bad luck. Any representation of 3D rotations in a Euclidean space of four or fewer dimensions must be discontinuous somewhere; a neural network is itself a continuous function, and to fit a label that jumps, it has to force its way through the region around the jump. The rotation vector (axis-angle), with only 3 numbers, can't escape either: once the rotation angle passes 180°, the axis has to flip to the opposite direction. Zhou et al. also gave a continuous representation, the 6D in the bottom panel of the figure.

What About Regressing 9 Numbers Directly?

The rotation matrix itself is continuous, and each rotation has exactly one matrix. The problem is that 9 numbers from a network won't obligingly satisfy RRT=IRR^T=I: the three columns have to be mutually perpendicular unit vectors, and the determinant has to be +1 on top of that. Regress 9 numbers directly, and afterward you have to find the nearest rotation matrix, for example with SVD. TriNet, in the comparison tables later, predicts the matrix's three unit vectors and adds an orthogonality loss.

Bins

The other issue is binning. Since Hopenet, quite a few methods cut angles into bins for classification and then regress the details. The paper argues that binning throws away information.

Take that claim with a grain of salt. Hopenet takes the expected value of the bin probabilities, so its output is a continuous angle whose resolution isn't limited by the bin width. What bins really limit is the range; 66 bins of 3° only cover ±99°, and extending beyond that means adding bins, which is how WHENet extended yaw to the full circle in 2020.

So the question for this paper is what the network should output, and how the loss should be measured, once the labels become rotation matrices.

Solving the Problem

Architecture

Original Fig. 1: a flowchart from left to right. A yellow sheet labeled Image goes into a blue cube labeled RepVGG, followed by a red sheet labeled FC-Layer, the two enclosed in a dashed frame. The output is written as a matrix with two columns, a1 and a2, which passes through an arrow labeled f_GS to become a matrix with three columns, b1, b2 and b3, followed finally by a green rounded box labeled Geodesic Loss.
Original Fig. 1, Hempel et al., from PDF page 2, CC BY 4.0.

The whole method is this one figure. The backbone is RepVGG-B1g2, which the authors say is comparable in size to ResNet-50; it's followed by global average pooling and a single fully connected layer that outputs 6 numbers, arranged as two 3D vectors a1a_1 and a2a_2. fGSf_{GS} turns them into the three columns b1b_1, b2b_2, b3b_3 of a rotation matrix, and the geodesic loss is computed against the ground-truth matrix.

The authors tried one to three fully connected layers, as well as a separate branch for each output; a single layer with 6 outputs worked best. Compared with Hopenet's three 66-class classification heads, the output layer shrinks from 3×66=1983\times66=198 numbers to 6.

During training, each RepVGG block has three branches, 3×33\times3, 1×11\times1 and identity, which are merged into a single 3×33\times3 convolution at deployment, with the same accuracy and faster inference.

From 6 Numbers Back to a Rotation Matrix

The three columns of a rotation matrix are mutually perpendicular with length 1, and the third column is determined by the first two: it's their cross product. So only the first two columns need to be kept. Equation (1) of the paper drops the matrix's third column:

gGS([ a1  a2  a3 ])=[ a1  a2 ]g_{GS}\big([\,a_1\ \ a_2\ \ a_3\,]\big)=[\,a_1\ \ a_2\,]

Going the other way, equation (2) uses Gram–Schmidt to complete any two vectors into a rotation matrix:

fGS([ a1  a2 ])=[ b1  b2  b3 ]f_{GS}\big([\,a_1\ \ a_2\,]\big)=[\,b_1\ \ b_2\ \ b_3\,]

Equation (3) is three steps:

b1=a1∥a1∥u2=a2−(b1⋅a2) b1,b2=u2∥u2∥b3=b1×b2\begin{aligned} b_1&=\frac{a_1}{\|a_1\|}\\ u_2&=a_2-(b_1\cdot a_2)\,b_1,\qquad b_2=\frac{u_2}{\|u_2\|}\\ b_3&=b_1\times b_2 \end{aligned}

Walk through it with some numbers. Suppose the network outputs a1=(3,0,4)a_1=(3, 0, 4) and a2=(1.2,2,1.6)a_2=(1.2, 2, 1.6).

A diagram drawn for this note. On the left, a gray box is the plane spanned by b1 and b2: the blue arrow a1 runs right along the horizontal axis, 5 units long; the orange arrow a2 points up and to the right from the origin to (2, 2); a gray dashed line drops straight down from the tip of a2 to the horizontal axis, and a thick purple line marks a2's projection onto the b1 direction, (b1·a2) b1 = 2 b1; the green arrow u2 points straight up from the origin, 2 units long; two short black arrows are the unit-length b1 and b2; at the origin, a circle with a dot in the middle is labeled b3 (outward). On the right is the resulting matrix R, whose three columns, b1, b2 and b3, are (0.6, 0, 0.8), (0, 1, 0) and (−0.8, 0, 0.6), with a note below that as Euler angles it is pitch 0°, yaw −53.13°, roll 0°. Three lines of steps below: ① b1 = (3, 0, 4) / 5 = (0.6, 0, 0.8); ② b1·a2 = 0.72 + 0 + 1.28 = 2, u2 = a2 − 2 b1 = (0, 2, 0), b2 = (0, 1, 0); ③ b3 = (0.6, 0, 0.8) × (0, 1, 0) = (−0.8, 0, 0.6).
Drawn for this note from equations (1)–(3) of the paper; the numbers are an example.
  1. The first column keeps only the direction. ∥a1∥=9+16=5\|a_1\|=\sqrt{9+16}=5, b1=(0.6,0,0.8)b_1=(0.6, 0, 0.8). Multiplying a1a_1 by any positive number gives the same result, so the network doesn't have to guess a length.
  2. The second column loses its overlap with the first. b1⋅a2=0.6×1.2+0.8×1.6=2b_1\cdot a_2=0.6\times1.2+0.8\times1.6=2, meaning a2a_2 has 2 units along b1b_1. Remove that and u2=(1.2,2,1.6)−2 (0.6,0,0.8)=(0,2,0)u_2=(1.2, 2, 1.6)-2\,(0.6, 0, 0.8)=(0, 2, 0), perpendicular to b1b_1; scaled to unit length, b2=(0,1,0)b_2=(0, 1, 0).
  3. The third column is a cross product. b3=b1×b2=(0⋅0−0.8⋅1, 0.8⋅0−0.6⋅0, 0.6⋅1−0⋅0)=(−0.8,0,0.6)b_3=b_1\times b_2=(0\cdot0-0.8\cdot1,\ 0.8\cdot0-0.6\cdot0,\ 0.6\cdot1-0\cdot0)=(-0.8, 0, 0.6). The cross product guarantees that it's perpendicular to the first two columns with length 1, and that the three columns form a right-handed coordinate system with determinant +1.

Put together,

R=[0.60−0.80100.800.6]R=\begin{bmatrix}0.6&0&-0.8\\0&1&0\\0.8&0&0.6\end{bmatrix}

This is a rotation about the vertical axis only; converted back to Euler angles with the official code, it's pitch 0°, yaw −53.13°, roll 0°.

The 6 numbers the network outputs can be anything; as long as a1a_1 isn't the zero vector and a2a_2 isn't parallel to a1a_1, these three steps always give a valid rotation matrix. Conversely, any rotation matrix with its third column dropped is a 6D label, and the mapping is continuous in both directions. When the head turns θ\theta about the vertical axis, the first column is (cos⁡θ,0,−sin⁡θ)(\cos\theta, 0, -\sin\theta): smooth cosines and sines all the way around, with no jumps at all.

The official code reads like this (sixdrepnet/utils.py, with a few lines merged and comments added for this note):

Python
def compute_rotation_matrix_from_ortho6d(poses):   # poses: [B, 6]
    x_raw = poses[:, 0:3]                 # a1
    y_raw = poses[:, 3:6]                 # a2
    x = normalize_vector(x_raw)           # b1
    z = normalize_vector(cross_product(x, y_raw))   # b3 first
    y = cross_product(z, x)               # then b2 = b3 x b1
    return torch.cat((x.view(-1, 3, 1), y.view(-1, 3, 1), z.view(-1, 3, 1)), 2)

The order differs from equation (3): it finds the third column first and then goes back for the second, with the same result. a2a_2 can be split into u2u_2 plus a part along b1b_1, and the cross product of b1b_1 with itself is 0, so

b1×a2=b1×u2=∥u2∥ b3b_1\times a_2=b_1\times u_2=\|u_2\|\,b_3

Normalized, that's b3b_3; and b3×b1b_3\times b_1 is exactly b2b_2. Feed the numbers above into this code, and the matrix comes out the same as the hand calculation.

Geodesic Distance

Given a predicted matrix RpR_p and the ground truth RgtR_{gt}, we need to measure how far apart they are. The most direct way is to subtract the 9 elements and take L2; the authors consider that this misses the geometry of rotations and use the geodesic distance instead, that is, "the smallest angle you have to turn to get from one pose to the other." Equation (4) of the paper:

Lg=cos⁡−1 ⁣(tr⁡ ⁣(RpRgtT)−12)L_g=\cos^{-1}\!\left(\frac{\operatorname{tr}\!\left(R_pR_{gt}^T\right)-1}{2}\right)

To see where the formula comes from, note that RpRgtTR_pR_{gt}^T is itself a rotation, meaning "first turn the ground truth back to where it started, then turn to the prediction." Any rotation is a turn by some angle θ\theta about some axis; align a coordinate axis with that rotation axis, and the matrix looks like

[cos⁡θ−sin⁡θ0sin⁡θcos⁡θ0001]\begin{bmatrix}\cos\theta&-\sin\theta&0\\\sin\theta&\cos\theta&0\\0&0&1\end{bmatrix}

The diagonal sums to 1+2cos⁡θ1+2\cos\theta. Changing coordinates doesn't change the trace, so tr⁡(RpRgtT)=1+2cos⁡θ\operatorname{tr}(R_pR_{gt}^T)=1+2\cos\theta, and solving that back for the angle gives equation (4).

Try it on the earlier example. Suppose the ground truth is Ry(−50°)R_y(-50°), a −50° turn about the vertical axis only, and the prediction is the yaw −53.13° matrix above. The two differ by just a 3.13° rotation about the vertical axis; the trace is 1+2cos⁡3.13°≈2.9971+2\cos3.13°\approx2.997, and plugging it back in gives Lg=3.13°L_g=3.13° (training uses radians).

How does the geodesic distance differ from element-wise L2? Subtract the two matrices and take the Frobenius norm; once expanded, it depends only on θ\theta:

∥Rp−Rgt∥F=22 sin⁡θ2\|R_p-R_{gt}\|_F=2\sqrt2\,\sin\frac\theta2

For the example above, that's 0.0772. The two rank errors in the same order; the difference is in the gradient. Squared, it's 8sin⁡2θ28\sin^2\frac\theta2, roughly 2θ22\theta^2 when θ\theta is small, so the smaller the error, the weaker the push; the geodesic distance has a constant slope of 1 in θ\theta, pushing just as hard over the last few degrees as over the first few dozen. (This derivation is this note's own; the paper only says the Frobenius norm doesn't fit the geometry of SO(3).)

The official loss is short too (sixdrepnet/loss.py):

Python
class GeodesicLoss(nn.Module):
    def __init__(self, eps=1e-7):
        super().__init__()
        self.eps = eps

    def forward(self, m1, m2):
        m = torch.bmm(m1, m2.transpose(1, 2))              # R_p R_gt^T, [B, 3, 3]
        cos = (m[:, 0, 0] + m[:, 1, 1] + m[:, 2, 2] - 1) / 2
        theta = torch.acos(torch.clamp(cos, -1 + self.eps, 1 - self.eps))
        return torch.mean(theta)                            # radians

The clamp can't be dropped. The derivative of cos⁡−1\cos^{-1} at ±1 is infinite; when a prediction hits exactly, cos⁡=1\cos=1 and the gradient becomes NaN, and floating-point error can also push cos slightly above 1.

Training and Evaluation

As is customary, training uses only 300W-LP. The 3DDFA authors started from about 4,000 real photos in 300-W and used a 3D face model to turn the faces to all kinds of large angles, synthesizing 61,225 images, 122,450 with horizontal flips, labeled with Euler angles. The official code converts them into rotation matrices with Rz(roll)Ry(yaw)Rx(pitch)R_z(\text{roll})R_y(\text{yaw})R_x(\text{pitch}) to serve as training targets.

  • 30 epochs, Adam, a learning rate of 10−510^{-5} for the backbone and 10−410^{-4} for the fully connected layer, halved every 10 epochs, batch size 64. The first version of the official code, from February 2022, also sets the learning rate of RepVGG's first stage to 0, effectively freezing it, which the paper doesn't mention.
  • The official code's cropping and augmentation follow Hopenet: the box is taken from the landmarks and randomly enlarged, with flips at probability one half and blur at 5%; the input is 224×224224\times224.

Testing uses two real datasets. AFLW2000 is the first 2,000 in-the-wild photos of AFLW, for which the 3DDFA authors fitted ground-truth 3D faces and 68 landmarks, with large variation in pose, lighting and occlusion. BIWI is 15,678 images of 20 people turning their heads in front of a Kinect in a lab, with poses obtained by fitting a 3D head model to the depth point cloud; the heads are small in the frame, and the paper detects them with MTCNN and crops loosely. For both, following Hopenet and TriNet, only samples with all three angles between −99° and 99° are kept.

The metric is the MAE (mean absolute error) of the Euler angles. 6DRepNet first converts the predicted rotation matrix back to Euler angles; for each image, yaw, pitch and roll are each subtracted from the ground truth and the absolute value taken, then averaged over the whole test set, in degrees. With a true yaw of 30° and a prediction of 27°, that image records 3° in the yaw column. Averaging the MAEs of the three angles once more gives the last column of the table.

Discussion

Trained on 300W-LP, Tested on AFLW2000 and BIWI

The table shows the MAE of the three angles and their average, in degrees. Methods marked * are those the paper considers able to predict the full range of poses (for WHENet, yaw only).

MethodYawPitchRollMAE
Hopenet α=26.476.565.446.16
FSA-Net4.506.084.645.07
QuatNet3.975.623.924.50
WHENet-V4.445.754.314.83
WHENet*5.116.244.925.42
TriNet*4.045.774.204.67
FDN3.785.613.884.42
6DRepNet*3.634.913.373.97

Compiled from the AFLW2000 part of Table 1 of the paper, omitting the Hopenet α=1 and HPE rows.

On AFLW2000, all three angles and the average are the lowest in the table, at 3.97°. The main text says this beats the best method of the time by almost 20%, and the abstract says "up to 20%." The runner-up in the table is FDN at 4.42°, a gap of 0.45°, about 10%; to find a gap of 20% or more, you have to go down to FSA-Net's 5.07° (22%).

MethodYawPitchRollMAE
Hopenet α=14.816.613.274.90
FSA-Net4.274.962.764.00
QuatNet2.945.494.014.15
WHENet-V3.604.102.733.48
WHENet*3.994.393.063.81
TriNet*4.114.763.053.97
FDN4.524.702.563.93
6DRepNet*3.244.482.683.47

Compiled from the BIWI part of Table 1 of the paper, omitting the Hopenet α=2 and HPE rows.

On BIWI the average is 3.47°, practically tied with WHENet-V's 3.48°; column by column, QuatNet is best on yaw, WHENet-V on pitch and FDN on roll. The authors' reading is that other methods' errors vary widely across the three angles, while 6DRepNet's three angles are more balanced.

Switching to BIWI's own 70/30 train/test split (random, as in FSA-Net), 6DRepNet gets 2.69°, 2.92° and 2.36°, averaging 2.66°; the next best under the same conditions, TriNet, gets 2.80°.

The Full-Range Column

The paper says the "Full Range" column shows which methods are "in general able to predict full-range rotations," a question of whether the representation has a range limit. 6DRepNet gets the check mark because rotation matrices have no range limit; but it's trained only on 300W-LP, whose yaw only goes to about ±90°, and not a single head in it shows the back of the head.

In issue #24 (June 2022), someone asked directly whether the pretrained model could handle heads whose faces aren't visible. On June 22, the author answered that, as far as they knew, the datasets dedicated to head pose at the time only provided yaw within ±99°, that there had been suggestions to extract data from CMU Panoptic (see WHENet), and: "If you find a suitable dataset with full rotation appearance, let me know."

The paper's conclusion also lists this as the next step.

Ablation

SettingAFLW2000BIWI70/30
ℓ2 loss4.133.702.84
Geodesic loss3.973.472.66
ResNet-504.263.763.09
RepVGG3.973.472.66

The top two rows are compiled from Table 3 of the paper and the bottom two from Table 4; the numbers are the average MAE of the three angles. 70/30 is BIWI's own train/test split; the bottom two rows compare backbones, with RepVGG meaning RepVGG-B1g2 and everything else set as in 6DRepNet.

  1. The geodesic loss is slightly better than ℓ2. It's 0.16° to 0.23° lower on all three tests. The official training code still keeps torch.nn.MSELoss() in a comment on the loss line.
  2. The backbone matters more. Swapping RepVGG for ResNet-50 takes BIWI 70/30 from 2.66° to 3.09°. The authors stress that the ResNet-50 version's 4.26° on AFLW2000 is still the best in the table.

These two tables are missing one comparison. The 6D representation is the star of the paper, yet no experiment swaps the output back to Euler angles or quaternions with the same backbone and the same training setup. The ResNet-50 version of 6DRepNet gets 4.26°, and Hopenet, also on ResNet-50, gets 6.16°, but the two differ in cropping, augmentation, learning rate and training length; how much of that 1.9° comes from the representation can't be told from the tables.

The Authors' Sequel: 6DRepNet360

In September 2023, the same three authors released 6DRepNet360, with a journal version in IEEE TIP in 2024. The method keeps the 6D representation and the geodesic loss; what it adds is data. CMU Panoptic is a dome-shaped studio lined with cameras all around, with participants standing in a circle facing the center of the dome; the authors automatically generated head-pose annotations from every camera view, and most of the captured samples show the back of the head. These 113,914 images were merged with 300W-LP into 236,364 images covering the full circle of yaw.

The sequel switches the backbone to ResNet-50, trains for 80 epochs with batch size 80 and a learning rate of 10−410^{-4}, and adds augmentations such as random rotation of ±45°, random occlusion and color changes. From Table 1 of arXiv v1:

  • 6DRepNet retrained with this setup on 300W-LP only: AFLW2000 3.61°, BIWI 3.78°.
  • 6DRepNet360 trained on the merged data: AFLW2000 4.26°, BIWI 3.39°.

The first item can be compared directly with the ResNet-50 version in Table 4 of this paper. Same backbone, same training data, and AFLW2000 drops from 4.26° to 3.61°: changing only the training setup moves it 0.65°, four times the 0.16° between the geodesic loss and ℓ2 in Table 3. Yet the sequel's ablation says the performance comes mainly from the 6D representation and has almost nothing to do with the backbone (the ResNet-18 version gets 3.75°); the sequel didn't run the experiment that changes only the representation under the same training either.

The second item adds the full-range data, and AFLW2000 actually slips back to 4.26°, while BIWI improves. The authors' explanation is that Panoptic has plenty of pitch angles larger than 300W-LP's, which helps on BIWI.

Two Years Later, Someone Ran the Comparison

In 2024, Cobo, Valle, Buenaposada and Baumela ran this experiment, with the same network, the same training data and augmentation, and only the output representation changed. Besides MAE, Cobo et al. also report the geodesic error (GE), which is equation (4) above converted to degrees, computed for each image and then averaged.

  • Short range (trained on 300W-LP, tested on AFLW2000): Euler angles give an MAE of 3.26° and a GE of 5.29°; 6D gives 3.49° and 5.37°. Euler angles even come out slightly ahead.
  • Full range (CMU Panoptic, including heads facing away from the camera): the GE is 10.47° for Euler angles, 9.32° for quaternions and 7.70° for 6D, with Euler angles 36% higher than 6D. Cobo et al. also retrained with 6DRepNet's official code and got 8.08°, close to their own 6D network and also ahead of Euler angles and quaternions.

Euler angles jump at the profiles (90° and 270°), quaternions at the back of the head (180°). AFLW2000 and BIWI only test up to ±99°, so the network hardly ever goes near these places; the differences between representations only show up over the full range.

The same paper also points out that BIWI's annotations come from fitting depth point clouds while 300W-LP's come from 3DDFA, and the two reference frames differ by a fixed rotation. Estimating this rotation from the test set and removing it brings Cobo et al.'s 6D model on BIWI from an MAE of 3.98° down to 3.21°. Every method in the table trained on 300W-LP and tested on BIWI carries this offset.

The ±180° in the Evaluation Code

When the official test.py computes each angle's error, it doesn't simply take ∣θ^−θ∣|\hat\theta-\theta|; it takes the smallest of five values, ∣Δ∣|\Delta|, ∣Δ±360°∣|\Delta\pm360°| and ∣Δ±180°∣|\Delta\pm180°|. It's been this way since the first version in February 2022, and the paper doesn't mention it.

±360° is easy to understand, since 179° and −179° are only 2° apart. ±180° corresponds to the other Euler-angle solution. For the same rotation, (p,y,r)(p, y, r) and (p+180°, 180°−y, r+180°)(p+180°,\ 180°-y,\ r+180°) give exactly the same matrix. For a head at yaw 95° labeled (10°,95°,−5°)(10°, 95°, -5°), converting back with the official formula gives (−170°,85°,175°)(-170°, 85°, 175°).

AFLW2000's labels can go up to ±99°, but the conversion formula's yaw only reaches ±90°. For heads between 90° and 99°, even if the network's prediction is spot on, pitch and roll will each be off by 180°. The ±180° term counts this case back to 0, at the cost of also counting a single angle that really is 180° off as 0; the yaw column still keeps an error of 2(∣y∣−90°)2(|y|-90°).

This code is cleaning up the mess Euler angles leave once yaw crosses 90°. Scoring by Euler-angle MAE can't get around the very problem 6DRepNet set out to avoid; Cobo et al. conclude that MAE should be avoided in favor of the geodesic error.

Official Code and Reproduction

The official code is at thohemp/6DRepNet, under the MIT license, with a pip package, SixDRepNet. The demo finds faces with RetinaFace, counting only those with a confidence of at least 0.95, and enlarges each side of the box by 20% before sending it into the model; the training boxes leave an extra 40% to 80% at the top and 12% to 24% on the other three sides, so the two don't match. Going through the issues turns up a few things.

Run it with the defaults and you fall short. In issue #14 (March 24, 2022), someone retrained without changing any parameters and got 4.24° on AFLW2000, against the paper's 3.97°. The author replied that the same code and setup had been used, that hardware, initialization and data order all introduce randomness, and that adjusting the learning rate or decay was worth a try. Two months later (May 29, 2022), the author updated the default settings, saying they should make the reported results easier to reach, "or in my trainings even surpass them." In issue #19, a user retrained with the new settings, plus images of masked faces, and got 3.86°.

The new defaults aren't the paper's settings. The May 29 update changed train.py's defaults from 30 epochs, batch size 64 and two learning rates halved every 10 epochs to 80 epochs, batch size 80 and a single learning rate of 10−410^{-4}, with the learning rate scheduler off by default; train.py still had these defaults at its last change in March 2023, and 6DRepNet360's epochs, batch size and learning rate are the same set. In issue #45 (April 2023), someone asked why the scheduler was off, and the author answered, "The scheduler is not used in training. It had no impact on the final accuracy of our model when we tested different configurations, so we deactivated it." That answer matches the new defaults; what Section 3 of the paper describes, and what the first version of the code from February followed, is halving every 10 epochs.

The BIWI column uses a different set of weights. The official cloud folder has three weight files uploaded on February 25, 2022: 6DRepNet_300W_LP_AFLW2000.pth, 6DRepNet_300W_LP_BIWI.pth and 6DRepNet_70_30_BIWI.pth. The first two are both labeled 300W-LP in their file names, yet one is saved per test set; the paper doesn't explain which epoch the AFLW2000 and BIWI columns of Table 1 come from or how it was chosen. The person who opened issue #49 (July 21, 2023) tested the AFLW2000 weights on BIWI. AFLW2000 matched, but BIWI came out at 4.02° (pitch 5.59°), against the paper's 3.47° (pitch 4.48°), and the thread got no reply. Put 4.02° in Table 1's BIWI column and it ranks behind WHENet-V, WHENet, FDN, TriNet and FSA-Net (from first place to sixth). The person's BIWI preprocessing may differ from the paper's; BIWI cropping depends on MTCNN's boxes, and a different detector puts the boxes in different places. In issue #18 (April 2022), someone validating on their own data got 4.05°, and after switching to detecting with RetinaFace on the original images before cropping, the error went above 20°.

The model isn't small. In issue #37 (January 2023), someone complained that it was slow on CPU and that the weights file was over 135 MB; in April 2024 the author pointed to another repo, 6DRepNet_ros, with a MobileNet backbone.

Conclusion

6DRepNet switched head-pose labels from Euler angles to rotation matrices. The network outputs only 6 numbers, Gram–Schmidt turns them back into a rotation matrix, and the loss measures the geodesic distance between two rotations, sidestepping the gimbal lock Euler angles hit at yaw ±90° as well as the jumps that any representation in four or fewer dimensions must have. Trained on 300W-LP, it gets 3.97° on AFLW2000 and 3.47° on BIWI, the lowest average error in the table on both.

How much of that comes from 6D, the paper can't tell. The geodesic loss beats ℓ2 by only 0.16° to 0.23°, swapping the backbone matters more, and the comparison that changes only the representation under the same training was never run; when the authors reran the same ResNet-50 with a different training setup in the sequel, AFLW2000 dropped from 4.26° to 3.61°.

As a building block, though, it's well worth taking. The 6D output, Gram–Schmidt and the geodesic loss add up to a dozen or so lines, and replacing an Euler-angle regression head doesn't require touching the backbone; keep the clamp, so a prediction that hits exactly doesn't produce NaN. When comparing MAE with others, align both the error computation and the weights file: the official test.py counts angles that are 180° off as 0, and the 300W-LP weights come in two copies, one per test set.

The benefit of 6D only becomes measurable beyond ±99°. The authors' 6DRepNet360 in 2023 kept 6D and the geodesic loss and added CMU Panoptic's data of heads facing away from the camera; in 2024, Cobo et al. finally ran the experiment that changes only the representation, and on AFLW2000 Euler angles even came out slightly ahead, but on the full-range test that includes the back of the head, Euler angles' geodesic error was 36% higher than 6D's.