Proposed solution for extremely rotated aligned faces
Expected behavior
Profile-like images should have their head's vertical axis also vertically aligned to the cut-out even if the head is slightly tilted to the side.
Actual behavior
For faces in profile or close to profile positions, which are also tilted to the side, the cut-out is usually rotated so that in extreme cases the aligned face is nearly horizontal.
Steps to reproduce
See above.
Other relevant information
The issue is that in get_transform_mat most of the reference points are brows and eyes. In a tilted profile view, eyes are basically vertically aligned, leading to a rotation of the cut-out because there's not enough weight on the vertical axis. I came up with the following "solution" (there might be a better one) to increase the weight on the vertical axis, which significantly reduced nearly all problems related to these extreme rotations, except when there are very extreme head rotations. It also slightly increased the convergence speed of the training as there's less rotational variation in more frontal face images.
In get_transform_mat, the current line of code determining the transformation matrix is
mat = umeyama( np.concatenate ( [ image_landmarks[17:49] , image_landmarks[54:55] ] ) , landmarks_2D_new, True)[0:2]
I replaced this with the following lines of code, putting much more weight on the chin point (not sure which point exactly that is):
CHIN_WEIGHT = 30
mat = umeyama(
np.concatenate([image_landmarks[17:49], image_landmarks[54]*np.ones((CHIN_WEIGHT, 2))]),
np.concatenate([landmarks_2D_new[:-1], landmarks_2D_new[-1]*np.ones((CHIN_WEIGHT, 2))]),
True)[0:2]
This is a solution that works, but it's a bit hacky. Another one could be to average the eye reference points per eye and exclude the brows, so you have 3 points in the end from which to calculate the transformation matrix. The reason for excluding the brows is that they can be transformed asymmetrically, e.g. the axis between these points is not necessarily orthogonal to the face's vertical axis when only one brow is lifted, while eyes stay at the same point.
I hope this helps.
chin part is not a strong side of FAN detector, something along eye line certainly would be better.
chin part is not a strong side of FAN detector, something along eye line certainly would be better.
It's not about the FAN detector, it's about removing variance from the extracted dataset. To my understanding, the less the faces are randomly rotated, the better the prediction will be. This proposal simply reduces variance of the extracted dataset, after the face detector extracted the key points of the detected face. It reduces the likeliness that extracted faces are horizontal instead of vertical.