justadudewhohacks /face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js

★ 17,994⑂ 3,872👁 349⑃ 115● 847▤ 38
TypeScriptMITCreated 2018-05-19
Download: 0.22.20.22.2 ↓0.22.22020-03-22
+0
Daily
17,994
stars
3,872
forks
349
watchers
115
prs
847
issues
38
releases

README

face-api.js




JavaScript face recognition API for the browser and nodejs implemented on top of tensorflow.js core (tensorflow/tfjs-core)

!faceapi

 Click me for Live Demos!

 Tutorials

 face-api.js — JavaScript API for Face Recognition in the Browser with tensorflow.js
 Realtime JavaScript Face Tracking and Face Recognition using face-api.js’ MTCNN Face Detector
 Realtime Webcam Face Detection And Emotion Recognition - Video
 Easy Face Recognition Tutorial With JavaScript - Video
 Using face-api.js with Vue.js and Electron
 Add Masks to People - Gant Laborde on Learn with Jason

 Table of Contents

 Features
 Running the Examples
 face-api.js for the Browser
 face-api.js for Nodejs
 Usage
   Loading the Models
   High Level API
   Displaying Detection Results
   Face Detection Options
   Utility Classes
   Other Useful Utility
 Available Models
   Face Detection
   Face Landmark Detection
   Face Recognition
   Face Expression Recognition
   Age Estimation and Gender Recognition
 API Documentation

 Features

 Face Recognition

!face-recognition

 Face Landmark Detection

!face_landmark_detection

 Face Expression Recognition

!preview_face-expression-recognition

 Age Estimation & Gender Recognition

!age_gender_recognition



 Running the Examples

Clone the repository:

 bash
git clone https://github.com/justadudewhohacks/face-api.js.git


 Running the Browser Examples

 bash
cd face-api.js/examples/examples-browser
npm i
npm start


Browse to http://localhost:3000/.

 Running the Nodejs Examples

 bash
cd face-api.js/examples/examples-nodejs
npm i


Now run one of the examples using ts-node:

 bash
ts-node faceDetection.ts


Or simply compile and run them with node:

 bash
tsc faceDetection.ts
node faceDetection.js




 face-api.js for the Browser

Simply include the latest script from dist/face-api.js.

Or install it via npm:

 bash
npm i face-api.js




 face-api.js for Nodejs

We can use the equivalent API in a nodejs environment by polyfilling some browser specifics, such as HTMLImageElement, HTMLCanvasElement and ImageData. The easiest way to do so is by installing the node-canvas package.

Alternatively you can simply construct your own tensors from image data and pass tensors as inputs to the API.

Furthermore you want to install @tensorflow/tfjs-node (not required, but highly recommended), which speeds things up drastically by compiling and binding to the native Tensorflow C++ library:

 bash
npm i face-api.js canvas @tensorflow/tfjs-node


Now we simply monkey patch the environment to use the polyfills:

 javascript
// import nodejs bindings to native tensorflow,
// not required, but will speed up things drastically (python required)
import '@tensorflow/tfjs-node';

// implements nodejs wrappers for HTMLCanvasElement, HTMLImageElement, ImageData
import  as canvas from 'canvas';

import  as faceapi from 'face-api.js';

// patch nodejs environment, we need to provide an implementation of
// HTMLCanvasElement and HTMLImageElement
co

Top issues

Latest release

0.22.2 0.22.2 2020-03-22
- bumped tfjs-core to version 1.7.0

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON