ageitgey / face_recognition Goto Github PK
View Code? Open in Web Editor NEWThe world's simplest facial recognition api for Python and the command line
License: MIT License
The world's simplest facial recognition api for Python and the command line
License: MIT License
Hello, I tried your library and I must say it's pretty cool and does work ! But sometimes when I enter an image and want it to recognize who it belongs to, I get two people instead of one. Is there some sort of precentage of accuracy where we could take the higher one ?
How can the simple known/unknown example be modified to have a different confidence/treshold other then point 6?
face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/
I tried the cmd command:
pip2 install face_recognition
before downloading the files here in github and moving to the python2.7 path,
and got a MemoryError once the process reached 99%.
Tried again after doing all of the above and got the exact same results:
abcdeMacBook-Pro:examples abc$ python facerec_from_webcam.py
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp, line 583
Traceback (most recent call last):
File "facerec_from_webcam.py", line 44, in
cv2.imshow('Video', frame)
cv2.error: /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:583: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
Hello,
A few months ago, I saw the tutorial that, indirectly, originated this library, and, today, I finally had the need to implement a solution that uses facial recognition. However, I got stuck with a big problem when I started planning the data model: what's the best way to store the face features in a database (in order to optimize the search)?
Given the fact that the matches are not based on "perfect matches" (it deals with "similarity"), I'm having a real hard time to build the model. With what I have right now, I would have to load to the memory all the features' sets I have and then execute the comparisons. Given the current application that my project has, that approach wouldn't be a huge problem but... it could become one in the future.
If possible, could you guys, please, give some hints or point some articles/papers on that matter?
Description error:
gnss523@gnss523:~/Desktop/face_recognition-master/examples$ python find_facial_features_in_picture.py
Traceback (most recent call last):
File "find_facial_features_in_picture.py", line 5, in
image = face_recognition.load_image_file("biden.jpg")
File "/usr/local/lib/python2.7/dist-packages/face_recognition/api.py", line 62, in load_image_file
return scipy.misc.imread(filename, mode=mode)
TypeError: imread() got an unexpected keyword argument 'mode'
please tell my
thank you
I am really interested in using your library in the school I teach in with our Raspberry Pi computers. However most other facial recognition solutions I have looked at upload the picture to a server for analysis. Due to UK Data Protection laws this pretty much stops us using these in schools.
Is all of the processing carried out locally with your library or do the pictures get uploaded anywhere?
Any chance you could provide an example or some input on how to deploy this to Heroku or other similar services? Couldn't figure out how to get the original version using lua scripts to work on Heroku.
Some insight would be useful!
Thanks for all of this btw!
I tried to run face_recognition from the command line. The known faces input was a folder containing 4 jgg files, the unknown faces input was a folder containing 2 jpg files. On one of the known files, no face was detected. This caused the program to crash. When I remove the offending file (where no face was found), the program runs perfectly and returns a result for the two unknown faces.
mbp-van-wouter:kface wouter$ face_recognition /Users/wouter/Desktop/kface/known /Users/wouter/Desktop/kface/unknown
WARNING: No faces found in /Users/wouter/Desktop/kface/known/wouter.jpg. Ignoring file.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/bin/face_recognition", line 11, in <module>
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/face_recognition/cli.py", line 61, in main
known_names, known_face_encodings = scan_known_people(known_people_folder)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/face_recognition/cli.py", line 27, in scan_known_people
known_face_encodings.append(encodings[0])
IndexError: list index out of range
i need to work with opencv images , read an images with opencv then pass it to the face_recongition
please can that be done? if yes an example
THank you so much
Lafi
Hi,
I successfully installed your package. Thank you for providing convenient face recognition package. I wanted to inquire more about benchmark testing and accuracy. Do you have a paper or any additional references I could use for my research? Any statistical evidence or reference would be much appreciated.
Kind regards,
Almas M.
After trying everything to install this on windows 7 I gave up and made on a virtual machine a Linux Ubuntu system.
I tried on the terminal the following steps in the order I write them:
pip3 install face_recognition
--ERROR--
sudo apt-get install python3-pip
pip3 install face_recognition
--ERROR--
sudo apt-get install libboost-all-dev
sudo apt-get update
sudo apt-get install git
git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build
cd build
cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1;
--ERROR--
sudo apt-get install cmake
sudo apt-get upgrade
--EXIT Terminal and reenter to start from main path --
cd dlib
cd build
cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1
cmake --build .
cd ..
python3 setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
-- NO PERMISSION ERROR --
sudo python3 setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
-- ERROR --
I was trying to run the image compare algorithm and got the following error-- ImportError: No module named face_recognition. I downloaded the most recent version of face_recognition, so I'm not sure what could be going wrong.
Traceback (most recent call last):
File "ImageCompare.py", line 1, in <module>
import face_recognition
ImportError: No module named face_recognition
Hello and thank you for this great resource, please see if you can help me to the right direction to fix this error:
"I tried to run this example "facerec_from_webcam.py" and got the following error"
Traceback (most recent call last):
File "facecam.py", line 22, in
face_locations = face_recognition.face_locations(frame)
File "/home/namong/.local/lib/python3.5/site-packages/face_recognition/api.py", line 85, in face_locations
return [_rect_to_css(face) for face in _raw_face_locations(img, number_of_times_to_upsample)]
File "/home/namong/.local/lib/python3.5/site-packages/face_recognition/api.py", line 74, in _raw_face_locations
return face_detector(img, number_of_times_to_upsample)
RuntimeError: Unsupported image type, must be 8bit gray or RGB image."
-namong
It will be great to add Face Recognition web service (Flask?) demo in examples.
Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
Error while calling cudaGetDevice(&the_device_id) in file /tmp/pip-build-2o0Zpt/dlib/dlib/dnn/gpu_data.cpp:178. code: 35, reason: CUDA driver version is insufficient for CUDA runtime version
face_recognition ./known_people/ ./unknown_people/
was returning error message: AttributeError: 'module' object has no attribute 'imread'
pip3 install Pillow
then it worked. was just a module I hadn't installed
When I run program, I also get following error:
Intel MKL FATAL ERROR: Cannot load libmkl_core.dylib.
Anybody have any work around?
I installed dlib following the instructions. When running the recognize_face_in_pictures.py sample file (or any other command) I get the error below: Reason: image not found
$user: python3 recognize_faces_in_pictures.py
Traceback (most recent call last):
File "classify.py", line 1, in <module>
import face_recognition
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/face_recognition/__init__.py", line 7, in <module>
from .api import load_image_file, face_locations, face_landmarks, face_encodings, compare_faces
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/face_recognition/api.py", line 4, in <module>
import dlib
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/dlib-19.4.99-py3.6-macosx-10.6-intel.egg/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/dlib-19.4.99-py3.6-macosx-10.6-intel.egg/dlib/dlib.so, 2): Library not loaded: @rpath/libpng16.16.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/dlib-19.4.99-py3.6-macosx-10.6-intel.egg/dlib/dlib.so
Reason: image not found
I feel like the library detects and recognises people quite accurately using 1 sample image. Is it necessary to create a training set using several images to make it more accurate?
I installing dlib and when I run
python3 setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
in Raspberry Pi 3 and ram are not enough to run at 96% "object_detection.cpp.o" .
How to manipulate to install from another device and copy to Raspberry Pi 3
It's a bit embarrassing for a leading ML expert to release a project where the docs link in the README leads to an ugly 404 page: https://face-recognition.readthedocs.io
Whenever I try to run facerec_from_webcam_faster.py, I get the error below. Note that I have checked my local files, the image to be recognized is place appropriately.
OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /home/pi/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp, line 3229
Traceback (most recent call last):
File "pj_webcam.py", line 31, in <module>
small_frame = cv2.resize(frame, (1, 1), fx=0.01, fy=0.01)
cv2.error: /home/pi/opencv-3.1.0/modules/imgproc/src/imgwarp.cpp:3229: error: (-215) ssize.area() > 0 in function resize
when I am trying to import face_recognition module , it is displaying the below attribute error
even though model is available there
I suppose, dlib class "face_recognition_model_v1" is not taking the path of face_recognition_model or the face_recognition_model "dlib_face_recognition_resnet_model_v1.dat"
is corrupted that is available here: http://dlib.net/files/
>>> import face_recognition
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/face_recognition/__init__.py", line 7, in <module>
from .api import load_image_file, face_locations, face_landmarks, face_encodings, compare_faces
File "/usr/local/lib/python2.7/dist-packages/face_recognition/api.py", line 21, in <module>
face_encoder = dlib.face_recognition_model_v1(face_recognition_model)
AttributeError: 'module' object has no attribute 'face_recognition_model_v1'
>>> import face_recognition_models
>>> face_recognition_model = face_recognition_models.face_recognition_model_location()
>>> print face_recognition_model
/usr/local/lib/python2.7/dist-packages/face_recognition_models/models/dlib_face_recognition_resnet_model_v1.dat
Your renowned and well written blog post is using about OpenFace in the example section (Thank you so much for that). Is there a particular reason, you are using dlib's face encoder instead of openface's? Have you got a chance to compare the performance?
known_people directory has three images of each of four different people
pic1.jpg has 10 unidentified people in it, 2 of which are in known_people
pic2.jpg has 4 unidentified people in it, 1 of which is in known_people
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
gpu@gpu:~$ face_recognition known_people pic1.jpg
Traceback (most recent call last):
File "/usr/local/bin/face_recognition", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/face_recognition/cli.py", line 66, in main
test_image(image_to_check, known_names, known_face_encodings)
File "/usr/local/lib/python2.7/dist-packages/face_recognition/cli.py", line 40, in test_image
unknown_image = scipy.misc.imresize(unknown_image, scale_factor)
File "/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.py", line 490, in imresize
imnew = im.resize(size, resample=func[interp])
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1645, in resize
return self._new(self.im.resize(size, resample))
ValueError: height and width must be > 0
gpu@gpu:~$ face_recognition known_people pic2.jpg
Traceback (most recent call last):
File "/usr/local/bin/face_recognition", line 11, in
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/face_recognition/cli.py", line 66, in main
test_image(image_to_check, known_names, known_face_encodings)
File "/usr/local/lib/python2.7/dist-packages/face_recognition/cli.py", line 40, in test_image
unknown_image = scipy.misc.imresize(unknown_image, scale_factor)
File "/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.py", line 490, in imresize
imnew = im.resize(size, resample=func[interp])
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 1645, in resize
return self._new(self.im.resize(size, resample))
ValueError: height and width must be > 0
Firstly thanks for excellent project sharing. I successfully installed to api my raspberry pi and its dependencies. When i was trying in python idle, i took a error. It ıs showed at picture.
Do you have any suggestion about this error?
Regars
Hey, first of all Thank you so much for this library. Its Amazing.
When i run the script line by line, i get an error "Illegal Instruction" at the following line
"my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]"
The python terminal exits after this. Please let me know if i am doing something wrong.
I am using Linux Mint and i pip installed face_recognition (got all libraries including dlib installed)
Just install it local via pip with --user key.
CLI version (cli.py) is not avaiable as a separete face_recognition terminal command.
I actually don't know, if pip allows you to put simlinks or something like that, so you
have separete scripts you can execute on console.
AttributeError: 'module' object has no attribute 'load_image_file'
I have installed face_recognition using pip install face_recognition.
When I try to use the function load_image_file, I am getting the error
AttributeError: 'module' object has no attribute 'load_image_file'
I just gave what is given in the description.. is it changed in the new version?
This is a great repo!
Installed face_recognition and tried all examples (except webcam). So far works great.
While trying to do this on 10 unknown images and one known images:
face_recognition ./known_people/ ./unknown_pictures/
it takes around 15-20 seconds. Is there a way to do image comparison of one unknown image to large number of known images in ~2-3 seconds. Also, will this code run on GPU instance and will it reduce latency?
The resulting location/bounding boxes returned by face_recognition.face_locations(img)
can contain negative numbers. I don't know if this is intentional(if so then please enlighten me when this might be useful)
Basically to solve the problem is used max(0...)
Also the image that lead to the problem was: http://scd.france24.com/en/files/imagecache/france24_ct_api_bigger_169/article/image/french-students-assembly-two.jpg
I am runnning this on ubuntu 16.04 and I have it working on my python 2.7 and I was able to do face recognition successfully.Now I found a darkflow library which will allow me to do object detection too ,but it is in python 3 and I get this error when i tried to import face_recognition in python3.
And this library and the blog posts are amazing , thank you.
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import face_recognition
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/marvin/.local/lib/python3.5/site-packages/face_recognition/__init__.py", line 7, in <module>
from .api import load_image_file, face_locations, face_landmarks, face_encodings, compare_faces
File "/home/marvin/.local/lib/python3.5/site-packages/face_recognition/api.py", line 4, in <module>
import dlib
File "/home/marvin/.local/lib/python3.5/site-packages/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: libpng16.so.16: cannot open shared object file: No such file or directory
Is there a c port of this library (in order to improve the poor framerate i got ?)
Thx :)
Hi is it possible to implemenet MMOD CNN as face detector instead of or as alternative to HOG which is used currently?
http://blog.dlib.net/2016/10/easily-create-high-quality-object.html
This can even improve this awesome package!
Thank you!
I want to execute facerec_from_webcam_faster.py example
sudo python facerec_from_webcam_faster.py
Traceback (most recent call last):
File "startCam.py", line 65, in <module>
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
AttributeError: 'module' object has no attribute 'FILLED'
Hi, thanks for your amazing articles! :)
I was wondering how can we use more than 1 image for each person to do an embedding of the person in different conditions (light, beard/no beard, glasses, ...)?
I am new to this, correct me if I am wrong, we have to apply face_recognition.face_encodings(picture_of_me)[0]
to each image (20, 30) of every person, and then apply SVM in order to predict the class of new images? If so, what will happen if we test a new face that was not used when training the classifier?
Thank you!
Everything installed properly, but I am not able to import face_recognition
into my python.
>>> import face_recognition
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/conda/lib/python2.7/site-packages/face_recognition/__init__.py", line 7, in <module>
from .api import load_image_file, face_locations, face_landmarks, face_encodings, compare_faces
File "/opt/conda/lib/python2.7/site-packages/face_recognition/api.py", line 4, in <module>
import dlib
File "/opt/conda/lib/python2.7/site-packages/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: /opt/conda/lib/python2.7/site-packages/dlib/dlib.so: undefined symbol: _ZSt24__throw_out_of_range_fmtPKcz
Thanks for the creation of a great API! While the code runs smoothly, I'm curious if the dlib face encoding script performs an alignment with the face landmarks before encoding to the 128 length vector. There seems to be very little documentation on the dlib side how these encodings are generated, and I'm less familiar with that face recognition package. If you have any information on this it would be great to know and potentially add to your docs. Thanks.
Hi, Ageitgey
Database has a lot of face-coding, I want to do real-time face recognition. How to achieve? Loop or classifier?
Hi,
I'd like to package face_recognition for Debian. It would be very convenient if you could provide release tarballs.
Additionally, you might consider signing your releases. You can find more informations about it here.
Cheers,
Hugo (hle)
Like in your article on medium, you have said that to increase accuracy use more than one training images. How to use multiple images in your library?
One thing I can do that is to encode multiple images and give them same label.
Applying face_recognition.face_encodings to a few images. Some of them work fine, others show "list index out of range" error.
0, 1, 3 work; 2, 4 do not.
known_image = face_recognition.load_image_file("face_2.jpg")
known_encoding = face_recognition.face_encodings(known_image)[0]
when I run" recognize_faces_in_pictures.py"
gnss523@gnss523:~/Desktop/face_recognition-master/examples$ python find_faces_in_picture.py
Illegal instruction (core dumped)
how to slove erro
thanke you very much
In:
compare_faces(known_face_encodings, face_encoding_to_check, tolerance=0.6)
if known_face_encodings is an empty list, a non-intuitive ValueError is thrown. Created this issue so I can attach the pull request to it.
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
Hi! This project is sooo awesome! It sure has made face recognition very easy. However, I have a few concerns.
After testing this on a few of my images, there were a few results that were incorrect. Assuming the my images have different dimensions, the results were often inaccurate. Such as comparing two different persons would say that the unknown face was the known face, when in reality they were completely different persons.
I tried comparing a colored image of a person to a different person that was B&W. It also produced inaccurate results. The image size was also different.
So far those 2 things are what I've noticed. My images contains different sizes. Also, my images are BGR and some B&W.
Any suggestions on improving my results? Could it be caused by my inconsistent image dimensions, or their colors?
Thanks!
I'm trying to make just a few tests inspirer by the repo's examples.
import face_recognition as fr
image = fr.load_image_file('my_pic.jpg')
----> 3 image = fr.load_image_file('my_pic.jpg')
/usr/local/lib/python3.4/dist-packages/face_recognition/api.py in load_image_file(filename, mode)
60 :return: image contents as numpy array
61 """
---> 62 return scipy.misc.imread(filename, mode=mode)
63
64
TypeError: imread() got an unexpected keyword argument 'mode'
Thanks in advance !
I just installed your great project, and run the example(foo)
but I got the Segmentation fault: 11
aljundeMacBook-Pro-2:face_reco aljun$ python foo.py
Segmentation fault: 11
I have already installed the boost
and the python-boost
on my Mac
Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
The face_landmarks wrapper is missing two points from the _raw_face_landmarks output
I noticed the faces I draw using face_landmark were missing a bit of chin.
Turned out the chin only contains points 0 to 14 rather than 0 to 16. Two points are completely missing from the output.
Line where it happens : https://github.com/ageitgey/face_recognition/blob/master/face_recognition/api.py#L125
I'll see I have to time to contribute to try and correct this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.