yoloface icon indicating copy to clipboard operation
yoloface copied to clipboard

How To

Open ModynAI opened this issue 3 years ago • 13 comments

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

ModynAI avatar Oct 05 '21 10:10 ModynAI

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).

elyha7 avatar Oct 05 '21 14:10 elyha7

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 avatar Oct 05 '21 18:10 ModynAI

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

ModynAI avatar Oct 05 '21 18:10 ModynAI

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/

elyha7 avatar Oct 05 '21 20:10 elyha7

Thank you,

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

ModynAI avatar Oct 10 '21 07:10 ModynAI

How did you proceed to draw the boxes ?

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

AndreKev avatar May 13 '22 12:05 AndreKev

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)

elyha7 avatar May 13 '22 13:05 elyha7

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 avatar May 13 '22 14:05 AndreKev

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 avatar May 13 '22 15:05 AndreKev

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 avatar May 13 '22 15:05 AndreKev

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

AndreKev avatar May 13 '22 15:05 AndreKev

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.

elyha7 avatar May 13 '22 16:05 elyha7

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

AndreKev avatar May 16 '22 09:05 AndreKev