elyha7 / yoloface

Yolov5 Face Detection
GNU General Public License v3.0
120 stars 37 forks source link

How To #1

Open ModynAI opened 2 years ago

ModynAI commented 2 years ago

Hi, I can not use your Repo for inference.

I have 'cloned' your repo, 'cd' to it, then installed dependencies which has been mentioned in 'requirements.txt' and then used

from yoloface import YoloDetector
import numpy as np
from PIL import Image

model = YoloFace(target_size=720,gpu=0,min_face=90)
orgimg = np.array(Image.open('test_image.jpg'))
bboxes,points = model.predict(orgimg)

But it returns that yoloface is not installed!


ImportError Traceback (most recent call last)

in () ----> 1 from yoloface import YoloDetector 2 import numpy as np 3 from PIL import Image 4 5 model = YoloFace(target_size=720,gpu=0,min_face=90) /content/yoloface/yoloface.py in () 11 from math import sqrt 12 ---> 13 from .models.common import Conv 14 from .models.yolo import Model 15 from .utils.datasets import letterbox ImportError: attempted relative import with no known parent package --------------------------------------------------------------------------- NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt. --------------------------------------------------------------------------

How should i fix this?

Thanks Best regards

elyha7 commented 2 years ago

Changed repo's structure to use absolute imports, now your problem must be solved. If you want to import module outside the repo's folder, export path into PYTHONPATH (example in readme).

ModynAI commented 2 years ago

Thanks Its fixed Now. but i dont have output image

its just says that

0 /content/yoloface/weights/yolov5n_state_dict.pt WARNING: --img-size 612 must be multiple of max stride 32, updating to 640

How can i see the Bounding box position in the picture?

Thanks Best regards

ModynAI commented 2 years ago

Thanks to you, i can have the bboxes and points but is it possible to use it on webcam? as a real time face detection?

Thanks Best regards

elyha7 commented 2 years ago

Thanks to you, i can have the bboxes and points but is it possible to use it on webcam? as a real time face detection?

Thanks Best regards

Yeah, you can. Follow this guide, but use my detector instead of Haar cascade. https://realpython.com/face-detection-in-python-using-a-webcam/

ModynAI commented 2 years ago

Thank you,

Have you tries to add TENSORT for the model as there is in yolov5-face

AndreKev commented 2 years ago

How did you proceed to draw the boxes ?

Think it can be done by simply drawing boxes in bbox. Alright ?

elyha7 commented 2 years ago

How did you proceed to draw the boxes ?

Think it can be done by simply drawing boxes in bbox. Alright ?

You can use PIL, opencv or any other drawing library to draw bboxes and facial points. Here is an example using opencv.

for box,lm in zip(bboxes,points):
    x1,y1,x2,y2 = box
    orgimg = cv2.rectangle(orgimg,(x1,y1),(x2,y2),(255,0,0),3)
    for i in lm:
        x = i[0]
        y = i[1]
        orgimg = cv2.circle(orgimg, (x, y), 3, (0,255,0), -1)
AndreKev commented 2 years ago

i got an issue unpacking box.

This is how I fixed this

for box,lm in zip(bboxes,points):
    for x1,y1,x2,y2 in box :
        count += 1
        orgimg = cv2.rectangle(orgimg,(x1,y1),(x2,y2),(255,0,0),3)
        for i in lm:
            x = i[0][0]
            y = i[0][1]
            #orgimg = cv2.circle(orgimg, (x, y), 3, (0,255,0), 1)

I get an issue drawing the circle. x and y are not numbers but lists.

What do they represent ?

AndreKev commented 2 years ago

Furthermore, it seems like this model detects better with PIL images than with cv2 images. Loading the linked image with cv2 gives 5 recognized faces, and loading with PIL gives 7 faces.

Here is the image: 48

loading the image with PIL (your loading technique) 7 faces: new

Loading the image with cv2 5 faces: new

I think it is all about colormode. You can consider let me sending a pull request to update drawing engine.

Congratulations. Do you know how I can improve my detection ?

AndreKev commented 2 years ago

I just changes the minimum face size with PIL image rendering:

Result : new

Awesome ! But still to be improved since some faces aren't shaded

AndreKev commented 2 years ago

But I notice that in RGB some faces are detected and not in BGR, then vice versa !

elyha7 commented 2 years ago

But I notice that in RGB some faces are detected and not in BGR, then vice versa !

The models were trained with rgb images and opencv by default uses bgr color space, so ofc better accuracy in rgb. In opencv color space can be changed with cv2.cvtColor() method. If you need better accuracy for smaller faces, consider using other models from deepcam-cn repo, i use one of the lightest ones in my repo.

AndreKev commented 2 years ago

Alright but look at this image I link. You will notice that, some face are only detected in BGR (blue boxes) and not in RGB, then some face are only detected in RGB (red boxes) and not in BGR.

From hidden experience I think there is greater probability on detecting dark faces and faces with mufflers in BGR, but face detection in BGR outputs a little more false positives in these cases.

84_detected