6D Rotation Representation For Unconstrained Head Pose Estimation
- 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}
}
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 , or , 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 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 : 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 and roll as , and multiplying out gives
Only 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. , and 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 .

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 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 ; turning about a unit axis is . Quaternions have no gimbal lock, but and represent the same rotation. The usual way to give each rotation a single label is to require , 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 and one turned 190° is labeled , 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 : 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

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 and . turns them into the three columns , , 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 numbers to 6.
During training, each RepVGG block has three branches, , and identity, which are merged into a single 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:
Going the other way, equation (2) uses Gram–Schmidt to complete any two vectors into a rotation matrix:
Equation (3) is three steps:
Walk through it with some numbers. Suppose the network outputs and .

- The first column keeps only the direction. , . Multiplying by any positive number gives the same result, so the network doesn't have to guess a length.
- The second column loses its overlap with the first. , meaning has 2 units along . Remove that and , perpendicular to ; scaled to unit length, .
- The third column is a cross product. . 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,
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 isn't the zero vector and isn't parallel to , 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 about the vertical axis, the first column is : 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):
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. can be split into plus a part along , and the cross product of with itself is 0, so
Normalized, that's ; and is exactly . Feed the numbers above into this code, and the matrix comes out the same as the hand calculation.
Geodesic Distance
Given a predicted matrix and the ground truth , 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:
To see where the formula comes from, note that 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 about some axis; align a coordinate axis with that rotation axis, and the matrix looks like
The diagonal sums to . Changing coordinates doesn't change the trace, so , and solving that back for the angle gives equation (4).
Try it on the earlier example. Suppose the ground truth is , 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 , and plugging it back in gives (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 :
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 , roughly when is small, so the smaller the error, the weaker the push; the geodesic distance has a constant slope of 1 in , 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):
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 at ±1 is infinite; when a prediction hits exactly, 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 to serve as training targets.
- 30 epochs, Adam, a learning rate of for the backbone and 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 .
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).
| Method | Yaw | Pitch | Roll | MAE |
|---|---|---|---|---|
| Hopenet α=2 | 6.47 | 6.56 | 5.44 | 6.16 |
| FSA-Net | 4.50 | 6.08 | 4.64 | 5.07 |
| QuatNet | 3.97 | 5.62 | 3.92 | 4.50 |
| WHENet-V | 4.44 | 5.75 | 4.31 | 4.83 |
| WHENet* | 5.11 | 6.24 | 4.92 | 5.42 |
| TriNet* | 4.04 | 5.77 | 4.20 | 4.67 |
| FDN | 3.78 | 5.61 | 3.88 | 4.42 |
| 6DRepNet* | 3.63 | 4.91 | 3.37 | 3.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%).
| Method | Yaw | Pitch | Roll | MAE |
|---|---|---|---|---|
| Hopenet α=1 | 4.81 | 6.61 | 3.27 | 4.90 |
| FSA-Net | 4.27 | 4.96 | 2.76 | 4.00 |
| QuatNet | 2.94 | 5.49 | 4.01 | 4.15 |
| WHENet-V | 3.60 | 4.10 | 2.73 | 3.48 |
| WHENet* | 3.99 | 4.39 | 3.06 | 3.81 |
| TriNet* | 4.11 | 4.76 | 3.05 | 3.97 |
| FDN | 4.52 | 4.70 | 2.56 | 3.93 |
| 6DRepNet* | 3.24 | 4.48 | 2.68 | 3.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
| Setting | AFLW2000 | BIWI | 70/30 |
|---|---|---|---|
| ℓ2 loss | 4.13 | 3.70 | 2.84 |
| Geodesic loss | 3.97 | 3.47 | 2.66 |
| ResNet-50 | 4.26 | 3.76 | 3.09 |
| RepVGG | 3.97 | 3.47 | 2.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.
- 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. - 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 , 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 ; it takes the smallest of five values, , and . 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, and give exactly the same matrix. For a head at yaw 95° labeled , converting back with the official formula gives .
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 .
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 , 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.