face_recognition icon indicating copy to clipboard operation
face_recognition copied to clipboard

Having ValueError for some Images

Open apurva91 opened this issue 6 years ago • 3 comments

  • face_recognition version: 1.2.2
  • Python version: 3.6.5
  • Operating System: Ubuntu 18.04 x86_64

Description

I get this error when i preprocess the data and reuse it but when using cli it works fine

Traceback (most recent call last):
  File "detect_img.py", line 21, in <module>
    result = face_recognition.compare_faces(face_encodings, unknown_face)
  File "/home/apurva/FREC/frec/lib/python3.6/site-packages/face_recognition/api.py", line 212, in compare_faces
    return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance)
  File "/home/apurva/FREC/frec/lib/python3.6/site-packages/face_recognition/api.py", line 72, in face_distance
    return np.linalg.norm(face_encodings - face_to_compare, axis=1)
ValueError: operands could not be broadcast together with shapes (4,128) (2,128)

apurva91 avatar Aug 21 '18 09:08 apurva91

We can't really help you if you don't share your code.

ageitgey avatar Aug 21 '18 16:08 ageitgey

Your face encodings have a nested list. Delete and create new face encodings with the data set. This will work

karthik9319 avatar Jun 04 '20 05:06 karthik9319

this is because you give either a not valid known face encodings or a not valid known face .

make sure that both are lists of list of 128 number(encoding) : [ [ - 0,234234 , - 0,234234 , - 0,234234 , - 0,234234 , .... - 0,234234 ] ]

you may try to check :

if (len(face_encoding) == 1 and len(face_encoding[0] ==128 ) ) and (len(unkown_face) == 1 and len(unkown_face[0] ==128 ) ) : before you compare

mohamed3051215 avatar Sep 16 '21 10:09 mohamed3051215