Skip to content

Commit

Permalink
Support for new dlib 19.7 stuff (#185)
Browse files Browse the repository at this point in the history
* Support dlib 19.7 changes

* Typo fix

* README update
  • Loading branch information
ageitgey committed Oct 5, 2017
1 parent 3b8a16c commit 5f80487
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN apt-get install -y --fix-missing \

RUN cd ~ && \
mkdir -p dlib && \
git clone -b 'v19.5' --single-branch https://github.com/davisking/dlib.git dlib/ && \
git clone -b 'v19.7' --single-branch https://github.com/davisking/dlib.git dlib/ && \
cd dlib/ && \
python3 setup.py install --yes USE_AVX_INSTRUCTIONS

Expand Down
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
History
=======

1.1.0 (2017-09-23)
------------------

* Will use dlib's 5-point face pose estimator when possible for speed (instead of 68-point face pose esimator)
* dlib v19.7 is now the minimum required version
* face_recognition_models v0.3.0 is now the minimum required version


1.0.0 (2017-08-29)
------------------

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ See [this example](https://github.com/ageitgey/face_recognition/blob/master/exam

### Installation Options:

#### Installing on Mac or Linux
#### Installing on Mac or Linux

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

Expand All @@ -105,8 +105,8 @@ While Windows isn't officially supported, helpful users have posted instuctions

#### Installing a pre-configured Virtual Machine image

* [Download the pre-configured VM image](https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b) (for VMware Player or VirtualBox).
* [Download the pre-configured VM image](https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b) (for VMware Player or VirtualBox).

## Usage

#### Command-Line Interface
Expand Down Expand Up @@ -341,11 +341,11 @@ try `pip2 --no-cache-dir install face_recognition` to avoid the issue.

Issue: `AttributeError: 'module' object has no attribute 'face_recognition_model_v1'`

Solution: The version of `dlib` you have installed is too old. You need version 19.5 or newer. Upgrade `dlib`.
Solution: The version of `dlib` you have installed is too old. You need version 19.7 or newer. Upgrade `dlib`.

Issue: `Attribute Error: 'Module' object has no attribute 'cnn_face_detection_model_v1'`

Solution: The version of `dlib` you have installed is too old. You need version 19.5 or newer. Upgrade `dlib`.
Solution: The version of `dlib` you have installed is too old. You need version 19.7 or newer. Upgrade `dlib`.

Issue: `TypeError: imread() got an unexpected keyword argument 'mode'`

Expand Down
72 changes: 47 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,56 @@ for the code.
Installation
------------

Requirements:
Requirements
~~~~~~~~~~~~

- Python 3+ or Python 2.7
- macOS or Linux (Windows untested)
- `Also can run on a Raspberry Pi 2+ (follow these specific
instructions) <https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65>`__
- A `pre-configured VM
image <https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b>`__
is also available.
- Python 3.3+ or Python 2.7
- macOS or Linux (Windows not officially supported, but might work)

Install this module from pypi using ``pip3`` (or ``pip2`` for Python 2):
Installation Options:
~~~~~~~~~~~~~~~~~~~~~

.. code:: bash
Installing on Mac or Linux
^^^^^^^^^^^^^^^^^^^^^^^^^^

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

- `How to install dlib from source on macOS or
Ubuntu <https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf>`__

| IMPORTANT NOTE: It's very likely that you will run into problems when
pip tries to compile
| the ``dlib`` dependency. If that happens, check out this guide to
installing
| dlib from source (instead of from pip) to fix the error:
Then, install this module from pypi using ``pip3`` (or ``pip2`` for
Python 2):

`How to install dlib from
source <https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf>`__
.. code:: bash
| After manually installing ``dlib``, try running
``pip3 install face_recognition``
| again to complete your installation.
pip3 install face_recognition
| If you are still having trouble installing this, you can also try out
this
| If you are having trouble with installation, you can also try out a
| `pre-configured
VM <https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b>`__.
Installing on Raspberry Pi 2+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- `Raspberry Pi 2+ installation
instructions <https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65>`__

Installing on Windows
^^^^^^^^^^^^^^^^^^^^^

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

- `@masoudr's Windows 10 installation guide (dlib +
face\_recognition) <https://github.com/ageitgey/face_recognition/issues/175#issue-257710508>`__

Installing a pre-configured Virtual Machine image
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- `Download the pre-configured VM
image <https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b>`__
(for VMware Player or VirtualBox).

Usage
-----

Expand Down Expand Up @@ -223,7 +239,7 @@ If you are using Python 3.4 or newer, pass in a

.. code:: bash
$ face_recognition -cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/
$ 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.

Expand Down Expand Up @@ -427,7 +443,13 @@ Issue:
``AttributeError: 'module' object has no attribute 'face_recognition_model_v1'``

Solution: The version of ``dlib`` you have installed is too old. You
need version 19.4 or newer. Upgrade ``dlib``.
need version 19.7 or newer. Upgrade ``dlib``.

Issue:
``Attribute Error: 'Module' object has no attribute 'cnn_face_detection_model_v1'``

Solution: The version of ``dlib`` you have installed is too old. You
need version 19.7 or newer. Upgrade ``dlib``.

Issue: ``TypeError: imread() got an unexpected keyword argument 'mode'``

Expand Down
2 changes: 1 addition & 1 deletion examples/recognize_faces_in_pictures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
unknown_image = face_recognition.load_image_file("obama2.jpg")

# Get the face encodings for each face in each image file
# Since there could be more than one face in each image, it returns a list of encordings.
# Since there could be more than one face in each image, it returns a list of encodings.
# But since I know each image only has one face, I only care about the first encoding in each image, so I grab index 0.
biden_face_encoding = face_recognition.face_encodings(biden_image)[0]
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
Expand Down
16 changes: 12 additions & 4 deletions face_recognition/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

face_detector = dlib.get_frontal_face_detector()

predictor_model = face_recognition_models.pose_predictor_model_location()
pose_predictor = dlib.shape_predictor(predictor_model)
predictor_68_point_model = face_recognition_models.pose_predictor_model_location()
pose_predictor_68_point = dlib.shape_predictor(predictor_68_point_model)

predictor_5_point_model = face_recognition_models.pose_predictor_five_point_model_location()
pose_predictor_5_point = dlib.shape_predictor(predictor_5_point_model)

cnn_face_detection_model = face_recognition_models.cnn_face_detector_model_location()
cnn_face_detector = dlib.cnn_face_detection_model_v1(cnn_face_detection_model)
Expand Down Expand Up @@ -143,12 +146,17 @@ def convert_cnn_detections_to_css(detections):
return list(map(convert_cnn_detections_to_css, raw_detections_batched))


def _raw_face_landmarks(face_image, face_locations=None):
def _raw_face_landmarks(face_image, face_locations=None, model="large"):
if face_locations is None:
face_locations = _raw_face_locations(face_image)
else:
face_locations = [_css_to_rect(face_location) for face_location in face_locations]

pose_predictor = pose_predictor_68_point

if model == "small":
pose_predictor = pose_predictor_5_point

return [pose_predictor(face_image, face_location) for face_location in face_locations]


Expand Down Expand Up @@ -186,7 +194,7 @@ def face_encodings(face_image, known_face_locations=None, num_jitters=1):
:param num_jitters: How many times to re-sample the face when calculating encoding. Higher is more accurate, but slower (i.e. 100 is 100x slower)
:return: A list of 128-dimentional face encodings (one for each face in the image)
"""
raw_landmarks = _raw_face_landmarks(face_image, known_face_locations)
raw_landmarks = _raw_face_landmarks(face_image, known_face_locations, model="small")

return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]

Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
history = history_file.read()

requirements = [
'face_recognition_models>=0.2.0',
'face_recognition_models>=0.3.0',
'Click>=6.0',
'dlib>=19.5',
'dlib>=19.7',
'numpy',
'Pillow',
'scipy>=0.17.0'
Expand All @@ -25,7 +25,7 @@

setup(
name='face_recognition',
version='1.0.0',
version='1.1.0',
description="Recognize faces from Python or from the command line",
long_description=readme + '\n\n' + history,
author="Adam Geitgey",
Expand Down

0 comments on commit 5f80487

Please sign in to comment.