Commit c5cfd990 by vincent

added some notes for full face detection to face recognition pipeline in readme

parent ac739e3d
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* **[Face Detection](#usage-face-detection)** * **[Face Detection](#usage-face-detection)**
* **[Face Recognition](#usage-face-recognition)** * **[Face Recognition](#usage-face-recognition)**
* **[Face Landmark Detection](#usage-face-landmark-detection)** * **[Face Landmark Detection](#usage-face-landmark-detection)**
* **[Full Face Detection and Recognition Pipeline](#usage-full-face-detection-and-recognition-pipeline)**
## Examples ## Examples
...@@ -175,19 +176,6 @@ Or simply obtain the tensor (tensor has to be disposed manually): ...@@ -175,19 +176,6 @@ Or simply obtain the tensor (tensor has to be disposed manually):
const t = recognitionNet.forward('myImg') const t = recognitionNet.forward('myImg')
``` ```
Compute the Face Descriptors for Detected Faces:
``` javascript
const detections = await detectionNet.locateFaces(input)
// get the face tensors from the image (have to be disposed manually)
const faceTensors = await faceapi.extractFaceTensors(input, detections)
const descriptors = await Promise.all(faceTensors.map(t => recognitionNet.computeFaceDescriptor(t)))
// free memory for face image tensors after we computed their descriptors
faceTensors.forEach(t => t.dispose())
```
<a name="usage-face-landmark-detection"></a> <a name="usage-face-landmark-detection"></a>
### Face Landmark Detection ### Face Landmark Detection
...@@ -247,3 +235,39 @@ const landmarksByFace = await Promise.all(faceTensors.map(t => faceLandmarkNet.d ...@@ -247,3 +235,39 @@ const landmarksByFace = await Promise.all(faceTensors.map(t => faceLandmarkNet.d
// free memory for face image tensors after we computed their descriptors // free memory for face image tensors after we computed their descriptors
faceTensors.forEach(t => t.dispose()) faceTensors.forEach(t => t.dispose())
``` ```
<a name="usage-full-face-detection-and-recognition-pipeline"></a>
### Full Face Detection and Recognition Pipeline
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. You can easily align the faces from their face landmark positions as shown in the following example:
``` javascript
// first detect the face locations
const detections = await detectionNet.locateFaces(input)
// get the face tensors from the image (have to be disposed manually)
const faceTensors = (await faceapi.extractFaceTensors(input, detections))
// detect landmarks and get the aligned face image bounding boxes
const alignedFaceBoxes = await Promise.all(faceTensors.map(
async (faceTensor, i) => {
const faceLandmarks = await landmarkNet.detectLandmarks(faceTensor)
return faceLandmarks.align(detections[i])
}
))
// free memory for face image tensors after we detected the face landmarks
faceTensors.forEach(t => t.dispose())
// get the face tensors for the aligned face images from the image (have to be disposed manually)
const alignedFaceTensors = (await faceapi.extractFaceTensors(input, alignedFaceBoxes))
// compute the face descriptors from the aligned face images
const descriptors = await Promise.all(alignedFaceTensors.map(
faceTensor => recognitionNet.computeFaceDescriptor(faceTensor)
))
// free memory for face image tensors after we computed their descriptors
alignedFaceTensors.forEach(t => t.dispose())
```
\ No newline at end of file
...@@ -105,7 +105,7 @@ ...@@ -105,7 +105,7 @@
} }
)) ))
// free memory for face image tensors after we computed their descriptors // free memory for face image tensors after we detected the face landmarks
faceTensors.forEach(t => t.dispose()) faceTensors.forEach(t => t.dispose())
const alignedFaceTensors = (await faceapi.extractFaceTensors(input, alignedFaceBoxes)) const alignedFaceTensors = (await faceapi.extractFaceTensors(input, alignedFaceBoxes))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment