serengil/retinaface

When extracting faces, sometimes function will return empty array if face is not completely in view.

newbiemate opened this issue · 8 comments

I have a lot of photos that have groups of people in it. I was trying out this library to extract their face vector information, but it seems like when it encounters a face that's not fully in view (like cut off on the side), the face extraction function returns an empty array for that person.

Here is an example:

import matplotlib.pyplot as plt
from retinaface import RetinaFace

faces = RetinaFace.extract_faces(img_path = "test.jpg", align = True)
for face in faces:
  plt.imshow(face)
  plt.show()

The test image:
test

The above code will crash because on the very last person the function will return an empty array and matplotlib will fail due to trying to render something that has no data:

ie,

ValueError: zero-size array to reduction operation minimum which has no identity

RetinaFace will find everyone except the person on the very left, whose face is cut off. I'm new to face detection stuff, so I'm not sure if this is a bug or if deepface has a way to improve detection of these types of faces. Any help appreciated!

it worked for me

if you set the threshold to a lower value, then it will find faces easily.

https://github.com/serengil/retinaface/blob/master/retinaface/RetinaFace.py#L210

@serengil Could you share what values you used? I tried lowering it:

faces = RetinaFace.extract_faces(img_path = "test.jpg", align = True,  threshold=0.01)

But I'm still getting an empty array. Not sure if it makes a difference, but I'm not using CUDA to do any calculations:

Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
 Ignore above cudart dlerror if you do not have a GPU set up on your machine.

And I'm using a clean install of deepface, current build using pip install -e .

I used the default one. You can find the result in the attachment.

from retinaface import RetinaFace
import matplotlib.pyplot as plt

img_path = "x.jpg"

faces = RetinaFace.extract_faces(img_path = img_path, align = True)

for face in faces:
  plt.imshow(face)
  plt.show()

which version are you using? this is mine

(base) sefik@L-GCCDXDDT:~/workspace/facial-recognition-benchmarks-main$ pip show retina-face
Name: retina-face
Version: 0.0.13

Untitled

This is what I have:

Name: retina-face
Version: 0.0.15

This is my pip freeze:

absl-py==2.1.0
astunparse==1.6.3
beautifulsoup4==4.12.3
blinker==1.7.0
cachetools==5.3.3
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
contourpy==1.2.0
cycler==0.12.1
# Editable install with no version control (deepface==0.0.90)
-e c:\my programs\python projects\phototest\deepface-master
filelock==3.13.3
fire==0.6.0
Flask==3.0.2
flatbuffers==1.12
fonttools==4.50.0
gast==0.4.0
gdown==5.1.0
google-auth==2.29.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.62.1
gunicorn==21.2.0
h5py==3.10.0
idna==3.6
importlib_metadata==7.1.0
importlib_resources==6.4.0
itsdangerous==2.1.2
Jinja2==3.1.3
keras==2.9.0
Keras-Preprocessing==1.1.2
kiwisolver==1.4.5
libclang==18.1.1
Markdown==3.6
MarkupSafe==2.1.5
matplotlib==3.8.3
mtcnn==0.1.1
numpy==1.22.3
oauthlib==3.2.2
opencv-python==4.9.0.80
opt-einsum==3.3.0
packaging==24.0
pandas==2.0.3
Pillow==9.0.0
protobuf==3.19.6
pyasn1==0.6.0
pyasn1_modules==0.4.0
pyparsing==3.1.2
PySocks==1.7.1
python-dateutil==2.9.0.post0
pytz==2024.1
requests==2.31.0
requests-oauthlib==2.0.0
retina-face==0.0.15
rsa==4.9
six==1.16.0
soupsieve==2.5
tensorboard==2.9.1
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.9.0
tensorflow-estimator==2.9.0
tensorflow-io-gcs-filesystem==0.31.0
termcolor==2.4.0
tqdm==4.66.2
typing_extensions==4.10.0
tzdata==2024.1
urllib3==2.2.1
Werkzeug==3.0.1
wrapt==1.16.0
zipp==3.18.1

Okay I get the same error when upgrade to 15.

This is a bug. You can downgrade this to 13 not to have that error. Hope to sort this soon.

Closed with PR - #100