facenet-pytorch icon indicating copy to clipboard operation
facenet-pytorch copied to clipboard

Unaligned face and darkened result returned with certain config

Open Yosafat1997 opened this issue 3 years ago • 2 comments

I have small experiment to extract face from a photo. This is my config:

def face_detector(img):
    mdl = MTCNN(image_size=256, 
                          margin=0, 
                          min_face_size=20, 
                          thresholds=[0.6, 0.7, 0.7],
                          factor=0.709, 
                          select_largest=True,
                          selection_method="largest",
                          post_process=True, 
                          keep_all=False, 
                          device=device)
    detected,prob = mdl(img,return_prob=True)
    return detected,prob
    ```
when i plot original and the faces. some of them are unaligned to vertical position. And most of the image are darker than original image.

Yosafat1997 avatar May 28 '21 01:05 Yosafat1997

Alignment in literature is often understood only as cropped (and padded) so the center of the face would be the same for all faces [1]. In this case, the result of this MTCNN's implementation is aligned. If you want to rotate the face so the eyes line would make a vertical line, then you have to do it yourself. Admittedly, it's not always trivial. The result of MTCNN is a tensor of the face region of the image, post-processed through some normalization, so the value would be between [-1,+1]. Therefore, if you show them using plt.imshow(), some clipping would happen (imshow() expects float values in [0,1] only), which causes the image to appear darker. But for further processing in Resnet (for example embedding), it would not affect the outcome.

Sinuhe96 avatar Feb 18 '23 16:02 Sinuhe96

because face had normalization in the script of mtcnn.py, which name "fixed_image_standardization"

BooHwang avatar Mar 23 '23 02:03 BooHwang