face_recognition
face_recognition copied to clipboard
Having ValueError for some Images
- 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)
We can't really help you if you don't share your code.
Your face encodings have a nested list. Delete and create new face encodings with the data set. This will work
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