In this line of code in the api,
return np.linalg.norm(face_encodings - face_to_compare, axis=1).
I get an error TypeError: unsupported operand type(s) for -: 'list' and 'list'
I was running this code in the examples.
Any help is appreciated.
Can you post the entire output of you running the program and the full error you got?
I've met the same problem:

I make some changes in api.py.face_distance:

And it works!

I'm not very sure why it helps, maybe we cannot do operate the list directly.
This is my first comment on github and I do not know how to insert code correctly so I use pictures... Wish it helps. :)
You are getting this error because you are feeding the params face_encodings and face_to_compare with list objects instead of numpy.array. ex:
[1,2,3,4] - [2,3,4,5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'list' and 'list'
import numpy as np
np.array([1,2,3,4]) - np.array([2,3,4,5])
=> array([-1, -1, -1, -1])
The general rule when using face_recognition is that you should use the numpy.array for everything until you are done with processing and convert them into list at the end.
@deepseads :
This is my first comment on github and I do not know how to insert code correctly so I use pictures...
Click on the text "Styling with Markdown is supported" to learn about styling comments. But for code snippet, you can wrap it with backticks `like this`
@AlainPilon :
Thanks for your helpful reminds, I'm happy to learn so much on git hub.
I've figured out my problems and I do not need to modify the original codes. In my program, I was just trying the simple example:
import face_recognition
known_image = face_recognition.load_image_file("biden.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")
biden_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
It seems that I forgot to enter [0] s and [] of biden_enconding in my script, That makes the program do operations on the wrong objects.
@AlainPilon :
Thanks for your helpful reminds, I'm happy to learn so much on git hub.
I've figured out my problems and I do not need to modify the original codes. In my program, I was just trying the simple example:import face_recognition known_image = face_recognition.load_image_file("biden.jpg") unknown_image = face_recognition.load_image_file("unknown.jpg") biden_encoding = face_recognition.face_encodings(known_image)[0] unknown_encoding = face_recognition.face_encodings(unknown_image)[0] results = face_recognition.compare_faces([biden_encoding], unknown_encoding)It seems that I forgot to enter [0] s and [] of _biden_enconding_ in my script, That makes the program do operations on the wrong objects.
Can you justify where should I write [0] and what should I write [0]s or [] or [0] only.
Most helpful comment
You are getting this error because you are feeding the params
face_encodingsandface_to_comparewithlistobjects instead ofnumpy.array. ex:The general rule when using face_recognition is that you should use the numpy.array for everything until you are done with processing and convert them into list at the end.