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 To #1

Open
ModynAI opened this issue Oct 5, 2021 · 13 comments
Open

How To #1

ModynAI opened this issue Oct 5, 2021 · 13 comments

Comments

@ModynAI
Copy link

ModynAI commented Oct 5, 2021

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
Copy link
Owner

elyha7 commented Oct 5, 2021

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
Copy link
Author

ModynAI commented Oct 5, 2021

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
Copy link
Author

ModynAI commented Oct 5, 2021

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
Copy link
Owner

elyha7 commented Oct 5, 2021

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
Copy link
Author

ModynAI commented Oct 10, 2021

Thank you,

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

@AndreKev
Copy link

How did you proceed to draw the boxes ?

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

@elyha7
Copy link
Owner

elyha7 commented May 13, 2022

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
Copy link

AndreKev commented May 13, 2022

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
Copy link

AndreKev commented May 13, 2022

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
Copy link

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
Copy link

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

@elyha7
Copy link
Owner

elyha7 commented May 13, 2022

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
Copy link

AndreKev commented May 16, 2022

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

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