Skip to content

Commit 5f80487

Browse files
authored
Support for new dlib 19.7 stuff (ageitgey#185)
* Support dlib 19.7 changes * Typo fix * README update
1 parent 3b8a16c commit 5f80487

File tree

7 files changed

+77
-39
lines changed

7 files changed

+77
-39
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RUN apt-get install -y --fix-missing \
2929

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

HISTORY.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
History
22
=======
33

4+
1.1.0 (2017-09-23)
5+
------------------
6+
7+
* Will use dlib's 5-point face pose estimator when possible for speed (instead of 68-point face pose esimator)
8+
* dlib v19.7 is now the minimum required version
9+
* face_recognition_models v0.3.0 is now the minimum required version
10+
11+
412
1.0.0 (2017-08-29)
513
------------------
614

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ See [this example](https://github.com/ageitgey/face_recognition/blob/master/exam
7878

7979
### Installation Options:
8080

81-
#### Installing on Mac or Linux
81+
#### Installing on Mac or Linux
8282

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

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

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

108-
* [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).
109-
108+
* [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).
109+
110110
## Usage
111111

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

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

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

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

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

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

README.rst

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -87,40 +87,56 @@ for the code.
8787
Installation
8888
------------
8989

90-
Requirements:
90+
Requirements
91+
~~~~~~~~~~~~
9192

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

100-
Install this module from pypi using ``pip3`` (or ``pip2`` for Python 2):
96+
Installation Options:
97+
~~~~~~~~~~~~~~~~~~~~~
10198

102-
.. code:: bash
99+
Installing on Mac or Linux
100+
^^^^^^^^^^^^^^^^^^^^^^^^^^
103101

104-
pip3 install face_recognition
102+
First, make sure you have dlib already installed with Python bindings:
103+
104+
- `How to install dlib from source on macOS or
105+
Ubuntu <https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf>`__
105106

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

112-
`How to install dlib from
113-
source <https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf>`__
110+
.. code:: bash
114111
115-
| After manually installing ``dlib``, try running
116-
``pip3 install face_recognition``
117-
| again to complete your installation.
112+
pip3 install face_recognition
118113
119-
| If you are still having trouble installing this, you can also try out
120-
this
114+
| If you are having trouble with installation, you can also try out a
121115
| `pre-configured
122116
VM <https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b>`__.
123117
118+
Installing on Raspberry Pi 2+
119+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120+
121+
- `Raspberry Pi 2+ installation
122+
instructions <https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65>`__
123+
124+
Installing on Windows
125+
^^^^^^^^^^^^^^^^^^^^^
126+
127+
While Windows isn't officially supported, helpful users have posted
128+
instuctions on how to install this library:
129+
130+
- `@masoudr's Windows 10 installation guide (dlib +
131+
face\_recognition) <https://github.com/ageitgey/face_recognition/issues/175#issue-257710508>`__
132+
133+
Installing a pre-configured Virtual Machine image
134+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135+
136+
- `Download the pre-configured VM
137+
image <https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b>`__
138+
(for VMware Player or VirtualBox).
139+
124140
Usage
125141
-----
126142

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

224240
.. code:: bash
225241
226-
$ face_recognition -cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/
242+
$ face_recognition --cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/
227243
228244
You can also pass in ``--cpus -1`` to use all CPU cores in your system.
229245

@@ -427,7 +443,13 @@ Issue:
427443
``AttributeError: 'module' object has no attribute 'face_recognition_model_v1'``
428444

429445
Solution: The version of ``dlib`` you have installed is too old. You
430-
need version 19.4 or newer. Upgrade ``dlib``.
446+
need version 19.7 or newer. Upgrade ``dlib``.
447+
448+
Issue:
449+
``Attribute Error: 'Module' object has no attribute 'cnn_face_detection_model_v1'``
450+
451+
Solution: The version of ``dlib`` you have installed is too old. You
452+
need version 19.7 or newer. Upgrade ``dlib``.
431453

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

examples/recognize_faces_in_pictures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
unknown_image = face_recognition.load_image_file("obama2.jpg")
77

88
# Get the face encodings for each face in each image file
9-
# Since there could be more than one face in each image, it returns a list of encordings.
9+
# Since there could be more than one face in each image, it returns a list of encodings.
1010
# 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.
1111
biden_face_encoding = face_recognition.face_encodings(biden_image)[0]
1212
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]

face_recognition/api.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414

1515
face_detector = dlib.get_frontal_face_detector()
1616

17-
predictor_model = face_recognition_models.pose_predictor_model_location()
18-
pose_predictor = dlib.shape_predictor(predictor_model)
17+
predictor_68_point_model = face_recognition_models.pose_predictor_model_location()
18+
pose_predictor_68_point = dlib.shape_predictor(predictor_68_point_model)
19+
20+
predictor_5_point_model = face_recognition_models.pose_predictor_five_point_model_location()
21+
pose_predictor_5_point = dlib.shape_predictor(predictor_5_point_model)
1922

2023
cnn_face_detection_model = face_recognition_models.cnn_face_detector_model_location()
2124
cnn_face_detector = dlib.cnn_face_detection_model_v1(cnn_face_detection_model)
@@ -143,12 +146,17 @@ def convert_cnn_detections_to_css(detections):
143146
return list(map(convert_cnn_detections_to_css, raw_detections_batched))
144147

145148

146-
def _raw_face_landmarks(face_image, face_locations=None):
149+
def _raw_face_landmarks(face_image, face_locations=None, model="large"):
147150
if face_locations is None:
148151
face_locations = _raw_face_locations(face_image)
149152
else:
150153
face_locations = [_css_to_rect(face_location) for face_location in face_locations]
151154

155+
pose_predictor = pose_predictor_68_point
156+
157+
if model == "small":
158+
pose_predictor = pose_predictor_5_point
159+
152160
return [pose_predictor(face_image, face_location) for face_location in face_locations]
153161

154162

@@ -186,7 +194,7 @@ def face_encodings(face_image, known_face_locations=None, num_jitters=1):
186194
: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)
187195
:return: A list of 128-dimentional face encodings (one for each face in the image)
188196
"""
189-
raw_landmarks = _raw_face_landmarks(face_image, known_face_locations)
197+
raw_landmarks = _raw_face_landmarks(face_image, known_face_locations, model="small")
190198

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

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
history = history_file.read()
1111

1212
requirements = [
13-
'face_recognition_models>=0.2.0',
13+
'face_recognition_models>=0.3.0',
1414
'Click>=6.0',
15-
'dlib>=19.5',
15+
'dlib>=19.7',
1616
'numpy',
1717
'Pillow',
1818
'scipy>=0.17.0'
@@ -25,7 +25,7 @@
2525

2626
setup(
2727
name='face_recognition',
28-
version='1.0.0',
28+
version='1.1.0',
2929
description="Recognize faces from Python or from the command line",
3030
long_description=readme + '\n\n' + history,
3131
author="Adam Geitgey",

0 commit comments

Comments
 (0)