Skip to content

Commit 5877627

Browse files
update readme
1 parent f0d1946 commit 5877627

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,63 @@
22

33
**face recognition API for the browser with tensorflow.js**
44

5-
coming soon ...
5+
This project implements a ResNet-34 like architecture using the tensorflow.js core API ([@tensorflow/tfjs-core](https://github.com/tensorflow/tfjs-core)) for realtime face recognition in the browser. The neural net is equivalent to the *FaceRecognizerNet* used in [face-recognition.js](https://github.com/justadudewhohacks/face-recognition.js) and the net used in the [dlib](https://github.com/davisking/dlib/blob/master/examples/dnn_face_recognition_ex.cpp) face recognition example. The weights have been trained by [davisking](https://github.com/davisking) and the model achieves a prediction accuracy of 99.38% on the LFW (Labeled Faces in the Wild) benchmark for face recognition.
66

7-
![preview](https://user-images.githubusercontent.com/31125521/40273537-f4e88e82-5bc1-11e8-9472-a5f06087dfd7.gif)
7+
## Face Recognition
8+
9+
![preview_face-recognition](https://user-images.githubusercontent.com/31125521/40313021-c3afdfec-5d14-11e8-86df-cf89a00668e2.gif)
10+
11+
## Face Similarity
12+
13+
![preview_face-similarity](https://user-images.githubusercontent.com/31125521/40313983-6bade070-5d17-11e8-894c-6b4b52a2d61d.gif)
14+
15+
## Usage
16+
17+
Get the latest build from dist/face-recognition.min.js and include the script:
18+
19+
``` html
20+
<script src="face-recognition.min.js"></script>
21+
```
22+
23+
Download the weights file from your server and initialize the net (note, that your server has to host the *face_recognition_model.weights* file):
24+
25+
``` javascript
26+
const res = await axios.get('face_recognition_model.weights', { responseType: 'arraybuffer' })
27+
const weights = new Float32Array(res.data)
28+
const net = facerecognition.faceRecognitionNet(weights)
29+
```
30+
31+
Compute and compare two 150 x 150 sized face images:
32+
33+
``` javascript
34+
// input can be an ImageData object obtained from a 150 x 150 canvas via ctx.getImageData(0, 0, 150, 150)
35+
// or a flat array with length 3*150*150 with pixel values in rgb order
36+
// also have a look at the examples how to get the image data from a base64 string, from an <img>, from a <canvas> ...
37+
const imgData1 = ...
38+
const imgData2 = ...
39+
40+
41+
const descriptor1 = await net.computeFaceDescriptor(imgData1)
42+
const descriptor2 = await net.computeFaceDescriptor(imgData2)
43+
const distance = facerecognition.computeFaceDescriptor(descriptor1, descriptor2)
44+
45+
if (distance < 0.6)
46+
console.log('match')
47+
else
48+
console.log('no match')
49+
```
50+
51+
You can also get the face descriptor data synchronously:
52+
53+
``` javascript
54+
const desc = net.computeFaceDescriptorSync(imgData1)
55+
```
56+
57+
Or simply obtain the tensor:
58+
59+
``` javascript
60+
const t = net.forward(imgData1)
61+
```
862

963
## Running the examples
1064

0 commit comments

Comments
 (0)