Skip to content

Commit 4b4ecdb

Browse files
updated readme
1 parent 2f50aa1 commit 4b4ecdb

File tree

1 file changed

+27
-42
lines changed

1 file changed

+27
-42
lines changed

README.md

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Table of Contents:
2727
* **[Face Detection & 5 Point Face Landmarks - MTCNN](#usage-face-detection-mtcnn)**
2828
* **[Face Recognition](#usage-face-recognition)**
2929
* **[68 Point Face Landmark Detection](#usage-face-landmark-detection)**
30-
* **[Full Face Detection and Recognition Pipeline](#usage-full-face-detection-and-recognition-pipeline)**
30+
* **[Shortcut Functions for Full Face Description](#shortcut-functions)**
3131

3232
## Examples
3333

@@ -89,15 +89,15 @@ The face detection model has been trained on the [WIDERFACE dataset](http://mmla
8989

9090
### Face Detection - Tiny Yolo v2
9191

92-
The Tiny Yolo v2 based face detector can easily adapt to different input image sizes, thus can be used as an alternative to SSD Mobilenet v1 to trade off accuracy for performance (inference time). In general the model is not as accurate as SSD Mobilenet v1 but can achieve faster inference for lower image sizes.
92+
The Tiny Yolo v2 implementation is a very performant face detector, which can easily adapt to different input image sizes, thus can be used as an alternative to SSD Mobilenet v1 to trade off accuracy for performance (inference time). In general the models ability to locate smaller face bounding boxes is not as accurate as SSD Mobilenet v1.
9393

94-
The Tiny Yolo v2 implementation is still experimental, meaning there is room for optimization (future work). The trained model weights are provided in the [azFace](https://github.com/azmathmoosa/azFace) project.
94+
The face detector has been trained on a custom dataset of ~10K images labeled with bounding boxes and uses depthwise separable convolutions instead of regular convolutions, which ensures very fast inference and allows to have a quantized model size of only 1.7MB making the model extremely mobile and web friendly. Thus, the Tiny Yolo v2 face detector should be your GO-TO face detector on mobile devices.
9595

9696
<a name="about-face-detection-mtcnn"></a>
9797

9898
### Face Detection & 5 Point Face Landmarks - MTCNN
9999

100-
MTCNN (Multi-task Cascaded Convolutional Neural Networks) represents an alternative face detector to SSD Mobilenet v1 and Tiny Yolo v2, which offers much more room for configuration and is able to achieve much lower processing times. MTCNN is a 3 stage cascaded CNN, which simultanously returns 5 face landmark points along with the bounding boxes and scores for each face. By limiting the minimum size of faces expected in an image, MTCNN allows you to process frames from your webcam in realtime. Additionally with 2MB, the size of the weights file is only a third of the size of the quantized SSD Mobilenet v1 model (~6MB).
100+
MTCNN (Multi-task Cascaded Convolutional Neural Networks) represents an alternative face detector to SSD Mobilenet v1 and Tiny Yolo v2, which offers much more room for configuration. By tuning the input parameters, MTCNN is able to detect a wide range of face bounding box sizes. MTCNN is a 3 stage cascaded CNN, which simultanously returns 5 face landmark points along with the bounding boxes and scores for each face. By limiting the minimum size of faces expected in an image, MTCNN allows you to process frames from your webcam in realtime. Additionally with the model size is only 2MB.
101101

102102
MTCNN has been presented in the paper [Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks](https://kpzhang93.github.io/MTCNN_face_detection_alignment/paper/spl.pdf) by Zhang et al. and the model weights are provided in the official [repo](https://github.com/kpzhang93/MTCNN_face_detection_alignment) of the MTCNN implementation.
103103

@@ -164,7 +164,7 @@ await net.load('/models/face_detection_model-weights_manifest.json')
164164
// await net.load('/models/face_landmark_68_model-weights_manifest.json')
165165
// await net.load('/models/face_recognition_model-weights_manifest.json')
166166
// await net.load('/models/mtcnn_model-weights_manifest.json')
167-
// await net.load('/models/tiny_yolov2_model-weights_manifest.json')
167+
// await net.load('/models/tiny_yolov2_separable_conv_model-weights_manifest.json')
168168

169169
// or simply load all models
170170
await net.load('/models')
@@ -197,7 +197,7 @@ const maxResults = 10
197197

198198
// inputs can be html canvas, img or video element or their ids ...
199199
const myImg = document.getElementById('myImg')
200-
const detections = await faceapi.locateFaces(myImg, minConfidence, maxResults)
200+
const detections = await faceapi.ssdMobilenetv1(myImg, minConfidence, maxResults)
201201
```
202202

203203
Draw the detected faces to a canvas:
@@ -356,7 +356,7 @@ const rightEyeBrow = landmarks.getRightEyeBrow()
356356
Compute the Face Landmarks for Detected Faces:
357357

358358
``` javascript
359-
const detections = await faceapi.locateFaces(input)
359+
const detections = await faceapi.ssdMobilenetv1(input)
360360

361361
// get the face tensors from the image (have to be disposed manually)
362362
const faceTensors = await faceapi.extractFaceTensors(input, detections)
@@ -366,50 +366,35 @@ const landmarksByFace = await Promise.all(faceTensors.map(t => faceapi.detectLan
366366
faceTensors.forEach(t => t.dispose())
367367
```
368368

369-
<a name="usage-full-face-detection-and-recognition-pipeline"></a>
369+
<a name="shortcut-functions"></a>
370370

371-
### Full Face Detection and Recognition Pipeline
371+
### Shortcut Functions for Full Face Description
372372

373-
After face detection has been performed, I would recommend to align the bounding boxes of the detected faces before passing them to the face recognition net, which will make the computed face descriptor much more accurate. Fortunately, the api can do this for you under the hood. You can obtain the full face descriptions (location, landmarks and descriptor) of each face in an input image as follows:
373+
After face detection has been performed, I would recommend to align the bounding boxes of the detected faces before passing them to the face recognition net, which will make the computed face descriptor much more accurate. Fortunately, the api can do this for you under the hood by providing convenient shortcut functions. You can obtain the full face descriptions (location, landmarks and descriptor) of each face in an input image as follows.
374374

375-
``` javascript
376-
const fullFaceDescriptions = await faceapi.allFaces(input, minConfidence)
377-
378-
const fullFaceDescription0 = fullFaceDescriptions[0]
379-
console.log(fullFaceDescription0.detection) // bounding box & score
380-
console.log(fullFaceDescription0.landmarks) // 68 point face landmarks
381-
console.log(fullFaceDescription0.descriptor) // face descriptor
375+
Using the SSD Mobilenet v1 face detector + 68 point face landmark detector:
382376

377+
``` javascript
378+
const fullFaceDescriptions = await faceapi.allFacesSsdMobilenetv1(input, minConfidence)
383379
```
384380

385-
You can also do everything manually as shown in the following:
381+
Using the Tiny Yolo v2 face detector + 68 point face landmark detector:
386382

387383
``` javascript
388-
// first detect the face locations
389-
const detections = await faceapi.locateFaces(input, minConfidence)
390-
391-
// get the face tensors from the image (have to be disposed manually)
392-
const faceTensors = (await faceapi.extractFaceTensors(input, detections))
384+
const fullFaceDescriptions = await faceapi.allFacesTinyYolov2(input, { inputSize: 'md' })
385+
```
393386

394-
// detect landmarks and get the aligned face image bounding boxes
395-
const alignedFaceBoxes = await Promise.all(faceTensors.map(
396-
async (faceTensor, i) => {
397-
const faceLandmarks = await faceapi.detectLandmarks(faceTensor)
398-
return faceLandmarks.align(detections[i])
399-
}
400-
))
387+
Or with MTCNN face detection + 5 point face landmarks:
401388

402-
// free memory for face image tensors after we detected the face landmarks
403-
faceTensors.forEach(t => t.dispose())
404-
405-
// get the face tensors for the aligned face images from the image (have to be disposed manually)
406-
const alignedFaceTensors = (await faceapi.extractFaceTensors(input, alignedFaceBoxes))
389+
``` javascript
390+
const fullFaceDescriptions = await faceapi.allFacesMtcnn(input, { minFaceSize: 20 })
391+
```
407392

408-
// compute the face descriptors from the aligned face images
409-
const descriptors = await Promise.all(alignedFaceTensors.map(
410-
faceTensor => faceapi.computeFaceDescriptor(faceTensor)
411-
))
393+
The shortcut functions return an array of FullFaceDescriptions:
412394

413-
// free memory for face image tensors after we computed their descriptors
414-
alignedFaceTensors.forEach(t => t.dispose())
415-
```
395+
``` javascript
396+
const fullFaceDescription0 = fullFaceDescriptions[0]
397+
console.log(fullFaceDescription0.detection) // bounding box & score
398+
console.log(fullFaceDescription0.landmarks) // face landmarks
399+
console.log(fullFaceDescription0.descriptor) // face descriptor
400+
```

0 commit comments

Comments
 (0)