Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I change mtcnn to retinaface or other face detection model? How do I pass face aligment dots? #96

Open
martinenkoEduard opened this issue Apr 28, 2023 · 6 comments

Comments

@martinenkoEduard
Copy link

martinenkoEduard commented Apr 28, 2023

How do I change mtcnn to retinaface or other face detection model? How do I pass face alignment dots?
Can someone share a working example?

@ANDRESHZ
Copy link

ANDRESHZ commented May 8, 2023

Hi @martinenkoEduard, I used something that comment @mk-minchul #28 , I solved by the block of de "try: Except" into align.py file and call in there and evaluation model of retinaface or YOLO pretrained for example in prediction mode.

So into align.py at get_aligned_face function just change exception code to:

def get_aligned_face(image_path, rgb_pil_image=None):
    if rgb_pil_image is None:
        img = Image.open(image_path).convert('RGB')
    else:
        assert isinstance(rgb_pil_image, Image.Image), 'Face alignment module requires PIL image or path to the image'
        img = rgb_pil_image
    # find face
    try:
        bboxes, faces = mtcnn_model.align_multi(img, limit=1)
        face = faces[0]
    except Exception as e: #CHANGE CODE HERE!!!!
        width, height = img.size
        #Function to call YOLO or RetinaFace and obtain x, y , w and h [bbox in percentage % format ]
        results = model(img)  # this example use YOLO  created and instanced before using https://docs.ultralytics.com/tasks/detect/#val
        x, y, w, h= results2xywh(results) #send the biggest face identify at the image from YOLO format
        left = width*(x)
        top = height*(y)
        right = width*(w)
        bottom = height*(h)
        img2=img.crop((left, top, right, bottom))
        face=img2.resize((112,112))
        #print('Face detection Failed due to error.')
        #print(e)
        #face = None
    return face

you do not forget to reload the modules and import.

I hope to you help you @martinenkoEduard . I have been trying to training with custom data an I found #75.
Did you found some solution? or even you got a training well passed script? THAT WOULD BE GREAT!!

@martinenkoEduard
Copy link
Author

martinenkoEduard commented May 11, 2023

Hi @martinenkoEduard, I used something that comment @mk-minchul #28 , I solved by the block of de "try: Except" into align.py file and call in there and evaluation model of retinaface or YOLO pretrained for example in prediction mode.

So into align.py at get_aligned_face function just change exception code to:

def get_aligned_face(image_path, rgb_pil_image=None):
    if rgb_pil_image is None:
        img = Image.open(image_path).convert('RGB')
    else:
        assert isinstance(rgb_pil_image, Image.Image), 'Face alignment module requires PIL image or path to the image'
        img = rgb_pil_image
    # find face
    try:
        bboxes, faces = mtcnn_model.align_multi(img, limit=1)
        face = faces[0]
    except Exception as e: #CHANGE CODE HERE!!!!
        width, height = img.size
        #Function to call YOLO or RetinaFace and obtain x, y , w and h [bbox in percentage % format ]
        results = model(img)  # this example use YOLO  created and instanced before using https://docs.ultralytics.com/tasks/detect/#val
        x, y, w, h= results2xywh(results) #send the biggest face identify at the image from YOLO format
        left = width*(x)
        top = height*(y)
        right = width*(w)
        bottom = height*(h)
        img2=img.crop((left, top, right, bottom))
        face=img2.resize((112,112))
        #print('Face detection Failed due to error.')
        #print(e)
        #face = None
    return face

you do not forget to reload the modules and import.

I hope to you help you @martinenkoEduard . I have been trying to training with custom data an I found #75. Did you found some solution? or even you got a training well passed script? THAT WOULD BE GREAT!!

Btw - do you need to retrain model if you changed a face detector?
Or will work just fine?

I haven't found solution for this bug, yet..

@ANDRESHZ
Copy link

If you want to get better performance every time is necessary a fine tuning, but you can use a face detector is enough to get a nice results. @martinenkoEduard

@harvestingmoon
Copy link

Another simple solution you can try is using @insightface model. There they have a face_align under utils which uses ArcFace (together with SCRFD-10g) to align the facial features properly. However, it will be computationally expensive.

@martinenkoEduard
Copy link
Author

What about yolo5 trained on faces?
Has anyone tried it? Can someone share code with it?

@harvestingmoon
Copy link

I'd suggest sticking to MTCNN or TinaFace rather than using YOLOv5, accuracy in MTCNN is higher than YOLOv5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants