The world's simplest facial recognition api for Python and the command line

Overview

Face Recognition

You can also read a translated version of this file in Chinese 简体中文版 or in Korean 한국어 or in Japanese 日本語.

Recognize and manipulate faces from Python or from the command line with the world's simplest face recognition library.

Built using dlib's state-of-the-art face recognition built with deep learning. The model has an accuracy of 99.38% on the Labeled Faces in the Wild benchmark.

This also provides a simple face_recognition command line tool that lets you do face recognition on a folder of images from the command line!

PyPI Build Status Documentation Status

Features

Find faces in pictures

Find all the faces that appear in a picture:

import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_locations = face_recognition.face_locations(image)

Find and manipulate facial features in pictures

Get the locations and outlines of each person's eyes, nose, mouth and chin.

import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)

Finding facial features is super useful for lots of important stuff. But you can also use it for really stupid stuff like applying digital make-up (think 'Meitu'):

Identify faces in pictures

Recognize who appears in each photo.

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)

You can even use this library with other Python libraries to do real-time face recognition:

See this example for the code.

Online Demos

User-contributed shared Jupyter notebook demo (not officially supported): Deepnote

Installation

Requirements

  • Python 3.3+ or Python 2.7
  • macOS or Linux (Windows not officially supported, but might work)

Installation Options:

Installing on Mac or Linux

First, make sure you have dlib already installed with Python bindings:

Then, make sure you have cmake installed:

brew install cmake

Finally, install this module from pypi using pip3 (or pip2 for Python 2):

pip3 install face_recognition

Alternatively, you can try this library with Docker, see this section.

If you are having trouble with installation, you can also try out a pre-configured VM.

Installing on an Nvidia Jetson Nano board

  • Jetson Nano installation instructions
    • Please follow the instructions in the article carefully. There is current a bug in the CUDA libraries on the Jetson Nano that will cause this library to fail silently if you don't follow the instructions in the article to comment out a line in dlib and recompile it.

Installing on Raspberry Pi 2+

Installing on FreeBSD

pkg install graphics/py-face_recognition

Installing on Windows

While Windows isn't officially supported, helpful users have posted instructions on how to install this library:

Installing a pre-configured Virtual Machine image

Usage

Command-Line Interface

When you install face_recognition, you get two simple command-line programs:

  • face_recognition - Recognize faces in a photograph or folder full for photographs.
  • face_detection - Find faces in a photograph or folder full for photographs.

face_recognition command line tool

The face_recognition command lets you recognize faces in a photograph or folder full for photographs.

First, you need to provide a folder with one picture of each person you already know. There should be one image file for each person with the files named according to who is in the picture:

known

Next, you need a second folder with the files you want to identify:

unknown

Then in you simply run the command face_recognition, passing in the folder of known people and the folder (or single image) with unknown people and it tells you who is in each image:

$ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/

/unknown_pictures/unknown.jpg,Barack Obama
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person

There's one line in the output for each face. The data is comma-separated with the filename and the name of the person found.

An unknown_person is a face in the image that didn't match anyone in your folder of known people.

face_detection command line tool

The face_detection command lets you find the location (pixel coordinatates) of any faces in an image.

Just run the command face_detection, passing in a folder of images to check (or a single image):

$ face_detection  ./folder_with_pictures/

examples/image1.jpg,65,215,169,112
examples/image2.jpg,62,394,211,244
examples/image2.jpg,95,941,244,792

It prints one line for each face that was detected. The coordinates reported are the top, right, bottom and left coordinates of the face (in pixels).

Adjusting Tolerance / Sensitivity

If you are getting multiple matches for the same person, it might be that the people in your photos look very similar and a lower tolerance value is needed to make face comparisons more strict.

You can do that with the --tolerance parameter. The default tolerance value is 0.6 and lower numbers make face comparisons more strict:

$ face_recognition --tolerance 0.54 ./pictures_of_people_i_know/ ./unknown_pictures/

/unknown_pictures/unknown.jpg,Barack Obama
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person

If you want to see the face distance calculated for each match in order to adjust the tolerance setting, you can use --show-distance true:

$ face_recognition --show-distance true ./pictures_of_people_i_know/ ./unknown_pictures/

/unknown_pictures/unknown.jpg,Barack Obama,0.378542298956785
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person,None
More Examples

If you simply want to know the names of the people in each photograph but don't care about file names, you could do this:

$ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/ | cut -d ',' -f2

Barack Obama
unknown_person
Speeding up Face Recognition

Face recognition can be done in parallel if you have a computer with multiple CPU cores. For example, if your system has 4 CPU cores, you can process about 4 times as many images in the same amount of time by using all your CPU cores in parallel.

If you are using Python 3.4 or newer, pass in a --cpus <number_of_cpu_cores_to_use> parameter:

$ face_recognition --cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/

You can also pass in --cpus -1 to use all CPU cores in your system.

Python Module

You can import the face_recognition module and then easily manipulate faces with just a couple of lines of code. It's super easy!

API Docs: https://face-recognition.readthedocs.io.

Automatically find all the faces in an image
import face_recognition

image = face_recognition.load_image_file("my_picture.jpg")
face_locations = face_recognition.face_locations(image)

# face_locations is now an array listing the co-ordinates of each face!

See this example to try it out.

You can also opt-in to a somewhat more accurate deep-learning-based face detection model.

Note: GPU acceleration (via NVidia's CUDA library) is required for good performance with this model. You'll also want to enable CUDA support when compliling dlib.

import face_recognition

image = face_recognition.load_image_file("my_picture.jpg")
face_locations = face_recognition.face_locations(image, model="cnn")

# face_locations is now an array listing the co-ordinates of each face!

See this example to try it out.

If you have a lot of images and a GPU, you can also find faces in batches.

Automatically locate the facial features of a person in an image
import face_recognition

image = face_recognition.load_image_file("my_picture.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)

# face_landmarks_list is now an array with the locations of each facial feature in each face.
# face_landmarks_list[0]['left_eye'] would be the location and outline of the first person's left eye.

See this example to try it out.

Recognize faces in images and identify who they are
import face_recognition

picture_of_me = face_recognition.load_image_file("me.jpg")
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]

# my_face_encoding now contains a universal 'encoding' of my facial features that can be compared to any other picture of a face!

unknown_picture = face_recognition.load_image_file("unknown.jpg")
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]

# Now we can see the two face encodings are of the same person with `compare_faces`!

results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)

if results[0] == True:
    print("It's a picture of me!")
else:
    print("It's not a picture of me!")

See this example to try it out.

Python Code Examples

All the examples are available here.

Face Detection

Facial Features

Facial Recognition

Creating a Standalone Executable

If you want to create a standalone executable that can run without the need to install python or face_recognition, you can use PyInstaller. However, it requires some custom configuration to work with this library. See this issue for how to do it.

Articles and Guides that cover face_recognition

How Face Recognition Works

If you want to learn how face location and recognition work instead of depending on a black box library, read my article.

Caveats

  • The face recognition model is trained on adults and does not work very well on children. It tends to mix up children quite easy using the default comparison threshold of 0.6.
  • Accuracy may vary between ethnic groups. Please see this wiki page for more details.

Deployment to Cloud Hosts (Heroku, AWS, etc)

Since face_recognition depends on dlib which is written in C++, it can be tricky to deploy an app using it to a cloud hosting provider like Heroku or AWS.

To make things easier, there's an example Dockerfile in this repo that shows how to run an app built with face_recognition in a Docker container. With that, you should be able to deploy to any service that supports Docker images.

You can try the Docker image locally by running: docker-compose up --build

Linux users with a GPU (drivers >= 384.81) and Nvidia-Docker installed can run the example on the GPU: Open the docker-compose.yml file and uncomment the dockerfile: Dockerfile.gpu and runtime: nvidia lines.

Having problems?

If you run into problems, please read the Common Errors section of the wiki before filing a github issue.

Thanks

  • Many, many thanks to Davis King (@nulhom) for creating dlib and for providing the trained facial feature detection and face encoding models used in this library. For more information on the ResNet that powers the face encodings, check out his blog post.
  • Thanks to everyone who works on all the awesome Python data science libraries like numpy, scipy, scikit-image, pillow, etc, etc that makes this kind of stuff so easy and fun in Python.
  • Thanks to Cookiecutter and the audreyr/cookiecutter-pypackage project template for making Python project packaging way more tolerable.
Comments
  • Windows Installation Tutorial

    Windows Installation Tutorial

    Hi, I've successfully installed and tested this tool on my Windows 10 machine, and I'm writing a simple procedure to install it. It may be useful for some people to try to use this tool on a Windows machine.

    IMPORTANT: Actually, this project has been done for Linux systems, especially dlib. In my tests, the performance of this tool in Windows 10 was about a quarter compared to Ubuntu, built with the same specs. But I haven't seen any difference between these two in other subjects.

    Read First: The new version of dlib doesn't need Boost anymore, so you can skip it. Remember that you still need to meet the following requirements. Requirments: (I've used this tutorial with these tools installed on Windows 10, but the newer versions may work too.)

    1. Microsoft Visual Studio 2015 (or newer) with C/C++ Compiler installed. (Visual C++ 2015 Build Tools didn't work for me, and I got into problems in compiling dlib)
    2. Of course Python3 (I used Python3.5 x64 but the other versions may work too)
    3. CMake for windows and add it to your system environment variables.
    4. (ONLY FOR older versions of dlib) Boost library version 1.63 or newer. Also, you can use precompiled binaries for specific MSVC you have, but I don't suggest. (I've included the compiling procedure of Boost in this tutorial)

    Installation: Easy installation: Just install dlib and face_recognition (not always on the newest version): pip install dlib and then pip install face_recognition.

    Manual installation:

    1. Download and install scipy and numpy+mkl (must be mkl version) packages from this link (all credits goes to Christoph Gohlke). Remember to grab the correct version based on your current Python version.
    2. Download Boost library source code or binary release for your current MSVC from this link.
    3. If you downloaded the binary version skip to step 4 else, follow these steps to compile and build Boost by yourself: 3-1. Extract the Boost source files into C:\local\boost_1_XX_X (X means the current version of Boost you have) 3-2. Create a system variable with these parameters: Name: VS140COMNTOOLS Value: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\ (or any path where you have installed MSVC) 3-3. Open Developer Command Prompt for Visual Studio and go to the current directory of Boost extracted and try these commands to compile Boost: bootstrap b2 -a --with-python address-model=64 toolset=msvc runtime-link=static 3-4. If you successfully compile Boost, it should create compiled files in stage directory.
    4. (If you have already compiled Boost skip this step) If you already download the binary release, extract the contents to C:\local\boost_1_XX_X
    5. Grab the latest version of dlib from this repo and extract it.
    6. Go to dlibdirectory and open cmd and follow these commands to build dlib: (remember to replace XX with the current version of Boost you have) set BOOST_ROOT=C:\local\boost_X_XX_X set BOOST_LIBRARYDIR=C:\local\boost_X_XX_X\stage\lib python setup.py install --yes USE_AVX_INSTRUCTIONS or python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA
    7. Now, you can use import dlib without any problem in your python script.
    8. You can also check the current version of dlib with pip show dlib.
    9. Now, install face_recognition with pip install face_recognition.
    10. Enjoy!

    Finally, I need to say thanks to @ageitgey and @davisking for their awesome work.

    opened by masoudr 255
  • How can I make face recognition faster if I have more than 1M known images?

    How can I make face recognition faster if I have more than 1M known images?

    I tried to use your amazing project for face recognition (for example single unknown image) with my big number of known images (1 Million) but its really slow, this slow because its will load all known images (load_image_file -> then face_encodings) in order to compare with ONE unknown image file.

    Any ideas how to speed this process? I was thinking to do face_encodings for all known images then save the 128 as string into apache solr but with no luck as I still need to do compare_faces with all known images:) ... Any suggestions?

    opened by khaledabbad 78
  • Freeze your script with Pyinstaller

    Freeze your script with Pyinstaller

    Hi, You might want to freeze your script into a standalone executable to run on any system without the need of installing python or face_recognition and maybe you want to create a demo for your application and want to give it to someone else without giving your source code. Here is a simple tutorial to do that. I tested this method with python3.6 on Windows 10, but I think you can get it working on Linux with a similar method.

    1. Make sure you have correctly installed both face_recognition and dlib and you see no error when importing them into your script.
    2. Make sure your script works fine, and all its dependencies are right next to it, and you can run it fine with python yourscript.py.
    3. Install Pyinstallerwith pip: pip install pyinstaller
    4. Create a new directory and move your python script and all dependencies into it. I call it myproject and myscript.py
    5. Copy face_recognition_models and scipy-extra-dll from your python installed directory to your project directory.
    6. Create an empty file called <yourscriptname>.spec like myscript.spec next to your python script.
    7. Use below Pyinstaller spec file sample and edit some parts according to your needs: (I mark it with <> tag)
    # -*- mode: python -*-
    
    block_cipher = None
    
    face_models = [
    ('.\\face_recognition_models\\models\\dlib_face_recognition_resnet_model_v1.dat', './face_recognition_models/models'),
    ('.\\face_recognition_models\\models\\mmod_human_face_detector.dat', './face_recognition_models/models'),
    ('.\\face_recognition_models\\models\\shape_predictor_5_face_landmarks.dat', './face_recognition_models/models'),
    ('.\\face_recognition_models\\models\\shape_predictor_68_face_landmarks.dat', './face_recognition_models/models'),
    ]
    
    a = Analysis(['<your python script name.py>'],
                 pathex=['<path to working directory>'],
                 binaries=face_models,
                 datas=[],
                 hiddenimports=['scipy._lib.messagestream', 'scipy', 'scipy.signal', 'scipy.signal.bsplines', 'scipy.special', 'scipy.special._ufuncs_cxx',
                                'scipy.linalg.cython_blas',
                                'scipy.linalg.cython_lapack',
                                'scipy.integrate',
                                'scipy.integrate.quadrature',
                                'scipy.integrate.odepack',
                                'scipy.integrate._odepack',
                                'scipy.integrate.quadpack',
                                'scipy.integrate._quadpack',
                                'scipy.integrate._ode',
                                'scipy.integrate.vode',
                                'scipy.integrate._dop', 'scipy._lib', 'scipy._build_utils','scipy.__config__',
                                'scipy.integrate.lsoda', 'scipy.cluster', 'scipy.constants','scipy.fftpack','scipy.interpolate','scipy.io','scipy.linalg','scipy.misc','scipy.ndimage','scipy.odr','scipy.optimize','scipy.setup','scipy.sparse','scipy.spatial','scipy.special','scipy.stats','scipy.version'],
    
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher)
    
    a.datas += Tree('./scipy-extra-dll', prefix=None)
    
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              name='<your python script name>',
              debug=False,
              strip=False,
              upx=True,
              runtime_tmpdir=None,
              console=True )
    
    
    1. Generate your executable with python -m pyinstaller myscript.spec
    2. If you see no error then your executable can be found in dist directory.
    3. Enjoy!

    Thanks to @ageitgey and @davisking for their awesome work.

    opened by masoudr 55
  • What is the expected speed per image?

    What is the expected speed per image?

    First of all- this is awesome! Much better than OpenCV. No false positives so far while OpenCV had many. However it does about 1 image per second on my my Core i7. And I am just using face detection from this python library (no recognition). Is this a normal result? Feels a tad slow.

    opened by Dingo64 53
  • Illegal Instruction.

    Illegal Instruction.

    • face_recognition version: 0.1.9
    • Python version: 2.7
    • Operating System: Linux Mint

    Description

    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.

    What I Did

    I am using Linux Mint and i pip installed face_recognition (got all libraries including dlib installed)

    opened by abala003 30
  • How to install face_recognition?

    How to install face_recognition?

    There is something seriously wrong with this script. I tried 2 methods and both gave me nothing. I am trying on Debian 8 Amd64.

    Method 1 returns so many errors after the last command that it's insane:

    apt-get install libcurl3
    apt-get install cmake
    apt-get install git
    apt-get install python3.4
    apt-get install python3-pip
    apt-get install libboost-all-dev
    mkdir temporarydir
    cd temporarydir
    git clone https://github.com/davisking/dlib.git
    cd dlib
    mkdir build 
    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
    pip3 install scipy
    pip3 install face_recognition
    

    Method 2 is simpler:

    wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda-2.3.0-Linux-x86_64.sh
    bash Anaconda-2.3.0-Linux-x86_64.sh
    conda create -n py35 python=3.5
    activate py35
    conda config --add channels conda-forge
    conda install numpy
    conda install scipy
    conda install dlib
    pip install face_recognition
    conda install scipy
    

    As you can see I installed scipy twice and yet when I try to run face_recognition I get:

    Traceback (most recent call last):
      File "/usr/local/bin/face_recognition", line 7, in <module>
        from face_recognition.cli import main
      File "/usr/local/lib/python3.4/dist-packages/face_recognition/__init__.py", line 7, in <module>
        from .api import load_image_file, face_locations, face_landmarks, face_encodings, compare_faces, face_distance
      File "/usr/local/lib/python3.4/dist-packages/face_recognition/api.py", line 3, in <module>
        import scipy.misc
    ImportError: No module named 'scipy'
    
    opened by Dingo64 28
  • Problems installing face_recognition

    Problems installing face_recognition

    • face_recognition version: 1.2.3
    • Python version: 3.7.3
    • Operating System: Windows 10.0.17134.706

    Description

    I am simply trying to install face recognition for a project of mine and keep receiving this error.

    What I Did

    C:\Windows\system32>pip install face_recognition Collecting face_recognition Using cached https://files.pythonhosted.org/packages/3f/ed/ad9a28042f373d4633fc8b49109b623597d6f193d3bbbef7780a5ee8eef2/face_recognition-1.2.3-py2.py3-none-any.whl Collecting face-recognition-models>=0.3.0 (from face_recognition) Requirement already satisfied: Click>=6.0 in e:\new folder (2)\lib\site-packages (from face_recognition) (7.0) Collecting dlib>=19.7 (from face_recognition) Using cached https://files.pythonhosted.org/packages/05/57/e8a8caa3c89a27f80bc78da39c423e2553f482a3705adc619176a3a24b36/dlib-19.17.0.tar.gz Requirement already satisfied: Pillow in e:\new folder (2)\lib\site-packages (from face_recognition) (6.0.0) Requirement already satisfied: numpy in e:\new folder (2)\lib\site-packages (from face_recognition) (1.16.2) Building wheels for collected packages: dlib Building wheel for dlib (setup.py) ... error Complete output from command "e:\new folder (2)\python.exe" -u -c "import setuptools, tokenize;file='C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d C:\Users\walki\AppData\Local\Temp\pip-wheel-s06t1j5i --python-tag cp37: running bdist_wheel running build running build_py package init file 'dlib_init_.py' not found (or not a regular file) running build_ext Building extension for Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] Invoking CMake setup: 'cmake C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=e:\new folder (2)\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\build\lib.win-amd64-3.7 -A x64' -- Building for: NMake Makefiles CMake Error in CMakeLists.txt: Generator

      NMake Makefiles
    
    does not support platform specification, but platform
    
      x64
    
    was specified.
    

    CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred! See also "C:/Users/walki/AppData/Local/Temp/pip-install-76vhd65m/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log". Traceback (most recent call last): File "", line 1, in File "C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py", line 261, in 'Topic :: Software Development', File "e:\new folder (2)\lib\site-packages\setuptools_init_.py", line 145, in setup return distutils.core.setup(**attrs) File "e:\new folder (2)\lib\distutils\core.py", line 148, in setup dist.run_commands() File "e:\new folder (2)\lib\distutils\dist.py", line 966, in run_commands self.run_command(cmd) File "e:\new folder (2)\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "e:\new folder (2)\lib\site-packages\wheel\bdist_wheel.py", line 192, in run self.run_command('build') File "e:\new folder (2)\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "e:\new folder (2)\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "e:\new folder (2)\lib\distutils\command\build.py", line 135, in run self.run_command(cmd_name) File "e:\new folder (2)\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "e:\new folder (2)\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py", line 135, in run self.build_extension(ext) File "C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py", line 172, in build_extension subprocess.check_call(cmake_setup, cwd=build_folder) File "e:\new folder (2)\lib\subprocess.py", line 347, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['cmake', 'C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\tools\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\build\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=e:\new folder (2)\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\build\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.


    Failed building wheel for dlib Running setup.py clean for dlib Failed to build dlib Installing collected packages: face-recognition-models, dlib, face-recognition Running setup.py install for dlib ... error Complete output from command "e:\new folder (2)\python.exe" -u -c "import setuptools, tokenize;file='C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\walki\AppData\Local\Temp\pip-record-6482f4uw\install-record.txt --single-version-externally-managed --compile: running install running build running build_py package init file 'dlib_init_.py' not found (or not a regular file) running build_ext Building extension for Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] Invoking CMake setup: 'cmake C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=e:\new folder (2)\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\build\lib.win-amd64-3.7 -A x64' -- Building for: NMake Makefiles CMake Error in CMakeLists.txt: Generator

        NMake Makefiles
    
      does not support platform specification, but platform
    
        x64
    
      was specified.
    
    
    CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
    CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
    -- Configuring incomplete, errors occurred!
    See also "C:/Users/walki/AppData/Local/Temp/pip-install-76vhd65m/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py", line 261, in <module>
        'Topic :: Software Development',
      File "e:\new folder (2)\lib\site-packages\setuptools\__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "e:\new folder (2)\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "e:\new folder (2)\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "e:\new folder (2)\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "e:\new folder (2)\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "e:\new folder (2)\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "e:\new folder (2)\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "e:\new folder (2)\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "e:\new folder (2)\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "e:\new folder (2)\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "e:\new folder (2)\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py", line 135, in run
        self.build_extension(ext)
      File "C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py", line 172, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "e:\new folder (2)\lib\subprocess.py", line 347, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\walki\\AppData\\Local\\Temp\\pip-install-76vhd65m\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\walki\\AppData\\Local\\Temp\\pip-install-76vhd65m\\dlib\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=e:\\new folder (2)\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\walki\\AppData\\Local\\Temp\\pip-install-76vhd65m\\dlib\\build\\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.
    
    ----------------------------------------
    

    Command ""e:\new folder (2)\python.exe" -u -c "import setuptools, tokenize;file='C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\walki\AppData\Local\Temp\pip-record-6482f4uw\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\walki\AppData\Local\Temp\pip-install-76vhd65m\dlib\

    opened by WalkingCaesar09 26
  • Need To Uninstall dlib and face_recognition, getting 'face_recognition' has no attribute 'load_image_file'

    Need To Uninstall dlib and face_recognition, getting 'face_recognition' has no attribute 'load_image_file'

    • face_recognition version: The one on Github as of three days ago
    • Python version: 3.6
    • Operating System: Ubuntu

    Description

    face_recognition was working fine but then I tried to get dlib to use my GPU.
    I uninstalled as much of the two (dlib and face_recognition) as a could, installed dlib so that it would use my GPU, re-installed face_recognition, but I clearly didn't have a clean enough uninstall. Now when I try to use face_recognition I'm getting...
    $ python3 face.py Traceback (most recent call last): File "face.py", line 58, in image = face_recognition.load_image_file(aly) AttributeError: module 'face_recognition' has no attribute 'load_image_file'

    I know the problem is not with my code because, like I said, I worked before and it was using the CPU. The trouble started when I tried to get it to use the GPU. I know I should have done a full uninstallation of dlib and face_recognition but I don't know how. Know face_recognition and dlib documentation or Q&A problems up on the Internet anywhere explain this in a way that I can find/ make use of.

    Could you please help me uninstall these two modules, so I can get dlib re-installed the right way? Thank you.

    opened by MotorCityCobra 25
  • Facerec_from_video_file

    Facerec_from_video_file

    • face_recognition version: latest
    • Python version: 3.7.6
    • Operating System: Ubuntu 18.04

    Description

    Carry out facial recognition from video file, but use all CPU cores and/or GPU. Currently the script only maxes out one CPU core.

    What I Did

    Ran the script using PyCharm it starts processing the video file but only using 1 core of the CPU

    opened by JackAllen2020 21
  • Malloc - Runs Out Of Memory

    Malloc - Runs Out Of Memory

    • face_recognition version: latest
    • Python version: 3.6.3
    • Operating System: Arch Linux

    Description

    When attempting to identify faces, I use face_location with model="cnn". It should work but it instead fails.

    What I Did

    face_location = face_recognition.face_locations(image, model="cnn")
    
    Traceback (most recent call last):
      File "example.py", line 12, in <module>
        compare_faces(unknown_persons,known_list)
      File "/home/aaron/Development/bulk-image-facial-recognition/ml_face.py", line 36, in compare_faces
        recognize_faces(image)
      File "/home/aaron/Development/bulk-image-facial-recognition/ml_face.py", line 19, in recognize_faces
        face_locations = face_recognition.face_locations(image, model="cnn")
      File "/usr/lib/python3.6/site-packages/face_recognition/api.py", line 111, in face_locations
        return [_trim_css_to_bounds(_rect_to_css(face.rect), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, "cnn")]
      File "/usr/lib/python3.6/site-packages/face_recognition/api.py", line 95, in _raw_face_locations
        return cnn_face_detector(img, number_of_times_to_upsample)
    RuntimeError: Error while calling cudaMalloc(&data, new_size*sizeof(float)) in file /home/aaron/Development/tmp/dlib/dlib/dnn/gpu_data.cpp:195. code: 2, reason: out of memory
    
    opened by IWriteThings 17
  • IndexError: list index out of range

    IndexError: list index out of range

    IndexError: list index out of range

    my code:

    import face_recognition known_image = face_recognition.load_image_file("D:/1.jpg") unknown_image = face_recognition.load_image_file("D:/2.jpg") biden_encoding = face_recognition.face_encodings(known_image)[0]

    opened by wanesta 17
  • In Face Detection process, is it possible to form/generate an image of person whose faces got matched either self/ matching with some other face model

    In Face Detection process, is it possible to form/generate an image of person whose faces got matched either self/ matching with some other face model

    • face_recognition version: face_recognition-1.2.3
    • Python version: 3.9
    • Operating System: Linux distro, actually docker image : python:3.9-buster

    Description

    Describe what you were trying to get done : I have trained many people's face and stored their face-model with 128 nd array through pickle dump My detection is also working well, no issue with it When a person's face is recognized, I return the name of the person's even if I am getting multiple face found issues, but now I want to return the person's face to whomever it matches with. Please guide me through the conversion of face-model to image, any dlib-lib reference, or other would be a great help.

    opened by RoshanCubastion 0
  • Bump wheel from 0.29.0 to 0.38.1

    Bump wheel from 0.29.0 to 0.38.1

    Bumps wheel from 0.29.0 to 0.38.1.

    Changelog

    Sourced from wheel's changelog.

    Release Notes

    UNRELEASED

    • Updated vendored packaging to 22.0

    0.38.4 (2022-11-09)

    • Fixed PKG-INFO conversion in bdist_wheel mangling UTF-8 header values in METADATA (PR by Anderson Bravalheri)

    0.38.3 (2022-11-08)

    • Fixed install failure when used with --no-binary, reported on Ubuntu 20.04, by removing setup_requires from setup.cfg

    0.38.2 (2022-11-05)

    • Fixed regression introduced in v0.38.1 which broke parsing of wheel file names with multiple platform tags

    0.38.1 (2022-11-04)

    • Removed install dependency on setuptools
    • The future-proof fix in 0.36.0 for converting PyPy's SOABI into a abi tag was faulty. Fixed so that future changes in the SOABI will not change the tag.

    0.38.0 (2022-10-21)

    • Dropped support for Python < 3.7
    • Updated vendored packaging to 21.3
    • Replaced all uses of distutils with setuptools
    • The handling of license_files (including glob patterns and default values) is now delegated to setuptools>=57.0.0 (#466). The package dependencies were updated to reflect this change.
    • Fixed potential DoS attack via the WHEEL_INFO_RE regular expression
    • Fixed ValueError: ZIP does not support timestamps before 1980 when using SOURCE_DATE_EPOCH=0 or when on-disk timestamps are earlier than 1980-01-01. Such timestamps are now changed to the minimum value before packaging.

    0.37.1 (2021-12-22)

    • Fixed wheel pack duplicating the WHEEL contents when the build number has changed (#415)
    • Fixed parsing of file names containing commas in RECORD (PR by Hood Chatham)

    0.37.0 (2021-08-09)

    • Added official Python 3.10 support
    • Updated vendored packaging library to v20.9

    ... (truncated)

    Commits
    • 6f1608d Created a new release
    • cf8f5ef Moved news item from PR #484 to its proper place
    • 9ec2016 Removed install dependency on setuptools (#483)
    • 747e1f6 Fixed PyPy SOABI parsing (#484)
    • 7627548 [pre-commit.ci] pre-commit autoupdate (#480)
    • 7b9e8e1 Test on Python 3.11 final
    • a04dfef Updated the pypi-publish action
    • 94bb62c Fixed docs not building due to code style changes
    • d635664 Updated the codecov action to the latest version
    • fcb94cd Updated version to match the release
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Unable to locate images

    Unable to locate images

    • face_recognition version:
    • Python version:
    • Operating System:

    Description

    So I am trying to train my model what multiple images using SVM's SVC classifier While training the model, The face_recognition.face_locations(img) function is unable to detect images in a phone captured image While it is able to detect images with the webcam captured image
    I don't know what is wrong with it, the image quality on my phone is quit good as it has a 50MP camera Image details (will not be able to share the image due to confidentiality issues) type: JPEG width:2640px height:1188px Single face per single image

    What I have done

    I am currently using open CV and I have also tried to resize the images but it still is not detecting any face. ###Code

    #importing the libraries
    import face_recognition
    from sklearn import svm
    import numpy as np
    import os
    from datetime import datetime
    import cv2
    
    #Creating the lists to store encodings,names and classnames
    encodings=[]
    names=[]
    className=[]
    
    #Fetching the data to train the model from train_dir
    train_dir=os.listdir('./train_dir/')
    
    #loop for fetching the folder for each image
    for person in train_dir:
        print("Training model for : "+person)
        #creating a list to store all this folders
        pix=os.listdir("train_dir/"+person+"/")
        
        #loop to go thorough each folder and fetch images
        for person_img in pix:
            #loading the images to the algo
            face_img=face_recognition.load_image_file("train_dir/"+person+"/"+person_img)
            #Getting the face Locations for each image
            face_loc=face_recognition.face_locations(face_img)
            #the above function will retrun an array/List of tuples
            #Now if a face a single face is found in a image then one we will train our else we will discard that image
            if len(face_loc)==1:
                #Providing face to the algo to train
                face_enc=face_recognition.face_encodings(face_img)[0]
                #The above function will learing from the image and will remember the encodings
                #adding this encodings to the encoding list
                encodings.append(face_enc)
                #adding the name of the person to the names list
                names.append(person)
            #Checking the condition for more than one face
            elif len(face_loc)>1:
                print(person + "/" + person_img + " was skipped => More than one face was detected")
            #IF not face is detected then we can go to this  
            else:
                print(person + "/" + person_img + " was skipped => No face was detected")
    
    #Creating and training the SVC classifier
    clf =svm.SVC(gamma='scale')
    clf.fit(encodings,names)
    
    print("Training Complete")
    
    #defining a function  to make the attendence
    def markAttendence(name):
        with open('Attendence.csv','r+') as f:
            myDataList =f.readlines()
            nameList=[]
            for line in myDataList:
                entry =line.split(',')
                nameList.append(entry[0])
                if name not in nameList:
                    now = datetime.now()
                    dtString =now.strftime('%H:%M:%S')
                    f.writelines(f'\n{name},{dtString}')
    cap = cv2.VideoCapture(0)
    
    #Starting the process to read the video
    while True:
        #reading the input video frame by frame
        sucess,img = cap.read()
        #resizing the frames
        imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25)
        #Chanding the color to BGR
        imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)#To be reviewed
        encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
        #providing the location of the image to the model
        facesCurFrame = face_recognition.face_locations(imgS)
        #providing the encoding of the image to the model #first is the image and second is the face loaction
        for encodeFace,FaceLocation in zip(facesCurFrame,encodesCurFrame):
            #this matches each and every frame recived 
            matches=face_recognition.compare_faces(encodings,encodeFace)
            #the above function will retrun an array of true/false
    
            faceDis = face_recognition.face_distance(encodings, encodeFace)
    
            #This above fucntion will compare the distance both the face
            matchIndex=np.argmin(faceDis) #To be reviewed
            #If the name is found in our list then we provide a rectangel and display the name
            if matches[matchIndex]:
                name = name[matchIndex].upper
                y1,x2,y2,x1=FaceLocation
    
                y1,x2,y2,x1=y1*4,x2*4,y2*4,x1*4
    
                cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0),2)
                cv2.rectangle(img,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
                cv2.putText(img,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,255),2)
                markAttendence(name)
            else:
                namex="unknown"
                y1,x2,y2,x1=FaceLocation
    
                y1,x2,y2,x1=y1*4,x2*4,y2*4,x1*4
    
                cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0),2)
                cv2.rectangle(img,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
                cv2.putText(img,namex,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255,255,255),2)
                markAttendence(namex)
        cv2.imshow('WebCam',img)
        cv2.waitKey(1)
    
    opened by BirenMer 0
  • IndexError: list index out of range

    IndexError: list index out of range

    My code:

    analyze = DeepFace.analyze(img,  actions=['emotions']
            print(analyze)
            print(analyze['dominant_emotion'])
    

    The error I'm facing while running the code: IndexError: list index out of range

    opened by reshma-7span 0
  • Unqiue ID per face?

    Unqiue ID per face?

    More of a discussion, but is it possible to generate a unique ID from the facial recognition?

    The use case is I will scan an amount of images, get the face ID for each face it recognizes, and put it in a database, then whenever i submit an input image, it will get the face ID from the input and if that matches with any in the database it shows the corresponding info or whatever.

    is that possible with this? basically i'm asking if this code generates a unique ID for each unique face it detects. Is this value passed on somewhere? i can't see in the code what this value is saved as, if it does exist.

    opened by DankMemeGuy 0
Releases(v1.2.2)
Owner
Adam Geitgey
Adam Geitgey
A facial recognition device is a device that takes an image or a video of a human face and compares it to another image faces in a database.

A facial recognition device is a device that takes an image or a video of a human face and compares it to another image faces in a database. The structure, shape and proportions of the faces are compared during the face recognition steps.

Pavankumar Khot 4 Mar 19, 2022
Deskew is a command line tool for deskewing scanned text documents. It uses Hough transform to detect "text lines" in the image. As an output, you get an image rotated so that the lines are horizontal.

Deskew by Marek Mauder https://galfar.vevb.net/deskew https://github.com/galfar/deskew v1.30 2019-06-07 Overview Deskew is a command line tool for des

Marek Mauder 127 Dec 3, 2022
Handwritten Text Recognition (HTR) system implemented with TensorFlow (TF) and trained on the IAM off-line HTR dataset. This Neural Network (NN) model recognizes the text contained in the images of segmented words.

Handwritten-Text-Recognition Handwritten Text Recognition (HTR) system implemented with TensorFlow (TF) and trained on the IAM off-line HTR dataset. T

null 27 Jan 8, 2023
A curated list of resources for text detection/recognition (optical character recognition ) with deep learning methods.

awesome-deep-text-detection-recognition A curated list of awesome deep learning based papers on text detection and recognition. Text Detection Papers

null 2.4k Jan 8, 2023
Text recognition (optical character recognition) with deep learning methods.

What Is Wrong With Scene Text Recognition Model Comparisons? Dataset and Model Analysis | paper | training and evaluation data | failure cases and cle

Clova AI Research 3.2k Jan 4, 2023
Sign Language Recognition service utilizing a deep learning model with Long Short-Term Memory to perform sign language recognition.

Sign Language Recognition Service This is a Sign Language Recognition service utilizing a deep learning model with Long Short-Term Memory to perform s

Martin Lønne 1 Jan 8, 2022
This is an API written in python that uses FastAPI. It is a simple API that can detect discord tokens in Images.

Welcome This is an API written in python that uses FastAPI. It is a simple API that can detect discord tokens in Images. Installation There are curren

null 8 Jul 29, 2022
A Tensorflow model for text recognition (CNN + seq2seq with visual attention) available as a Python package and compatible with Google Cloud ML Engine.

Attention-based OCR Visual attention-based OCR model for image recognition with additional tools for creating TFRecords datasets and exporting the tra

Ed Medvedev 933 Dec 29, 2022
📷 Face Recognition using Haar-Cascade Classifier, OpenCV, and Python

Face-Recognition-System Face Recognition using Haar-Cascade Classifier, OpenCV and Python. This project is based on face detection and face recognitio

null 1 Jan 10, 2022
A curated list of papers and resources for scene text detection and recognition

Awesome Scene Text A curated list of papers and resources for scene text detection and recognition The year when a paper was first published, includin

Jan Zdenek 43 Mar 15, 2022
Detect handwritten words in a text-line (classic image processing method).

Word segmentation Implementation of scale space technique for word segmentation as proposed by R. Manmatha and N. Srimal. Even though the paper is fro

Harald Scheidl 190 Jan 3, 2023
Use Convolutional Recurrent Neural Network to recognize the Handwritten line text image without pre segmentation into words or characters. Use CTC loss Function to train.

Handwritten Line Text Recognition using Deep Learning with Tensorflow Description Use Convolutional Recurrent Neural Network to recognize the Handwrit

sushant097 224 Jan 7, 2023
Line based ATR Engine based on OCRopy

OCR Engine based on OCRopy and Kraken using python3. It is designed to both be easy to use from the command line but also be modular to be integrated

null 948 Dec 23, 2022
Create single line SVG illustrations from your pictures

Create single line SVG illustrations from your pictures

Javier Bórquez 686 Dec 26, 2022
Create single line SVG illustrations from your pictures

Create single line SVG illustrations from your pictures

Javier Bórquez 326 May 23, 2021
Ackermann Line Follower Robot Simulation.

Ackermann Line Follower Robot This is a simulation of a line follower robot that works with steering control based on Stanley: The Robot That Won the

Lucas Mazzetto 2 Apr 16, 2022
Handwritten Number Recognition using CNN and Character Segmentation

Handwritten-Number-Recognition-With-Image-Segmentation Info About this repository This Repository is aimed at reading handwritten images of numbers an

Sparsha Saha 17 Aug 25, 2022
TableBank: A Benchmark Dataset for Table Detection and Recognition

TableBank TableBank is a new image-based table detection and recognition dataset built with novel weak supervision from Word and Latex documents on th

null 844 Jan 4, 2023