2020-08-18 13:54:53 +02:00
# FaceAPI
2020-08-27 14:58:00 +02:00
## Note
2020-09-18 19:51:40 +02:00
This is updated **face-api.js** with latest available TensorFlow/JS as the original face-api.js is not compatible with **tfjs 2.0+** .
2020-08-27 14:58:00 +02:00
2020-08-22 18:13:02 +02:00
Forked from **face-api.js** version **0.22.2** released on March 22nd, 2020
- < https: // github . com / justadudewhohacks / face-api . js >
- < https: // www . npmjs . com / package / face-api . js >
2020-08-18 13:54:53 +02:00
## Differences
- Removed tests, docs, examples
- Updated all package dependencies
2020-09-18 19:51:40 +02:00
- Compatible with TensorFlow/JS 2.0+
- Updated type casting for TypeScript type checking
2020-08-22 18:13:02 +02:00
- Removed unnecesary package dependencies (karma, jasmine, etc.)
2020-10-11 18:41:17 +02:00
- Typescript build process now targets ES2018 and instead of dual ES5/ES6
2020-09-18 19:51:40 +02:00
- Browser bundle process uses ESBuild instead of Rollup
- New TensorFlow/JS dependencies since backends were removed from @tensorflow/tfjs -core
2020-08-26 18:43:33 +02:00
- Updated mobileNetv1 model due to batchNorm() dependency
2020-09-18 19:51:40 +02:00
- Fully tree shakable when imported as an ESM module
2020-10-11 18:41:17 +02:00
- Added `version` class that returns JSON object with version of FaceAPI as well as linked TFJS
- Added calls for `setPlatform` to automatically prepare TFJS in browser
2020-08-18 13:54:53 +02:00
- Removed following models as they are either obsolete or non-functional with tfjs 2.0+
- mtcnn: Mostly obsolete
- tinyYolov2: Non-functional since weights are missing
2020-08-26 00:24:48 +02:00
Which means valid models are **tinyFaceDetector** and **mobileNetv1**
2020-08-27 14:58:00 +02:00
Due to reduced code and changed build process, resulting bundle is about ** >5x smaller** than the original!
## Installation
2020-08-26 00:24:48 +02:00
2020-10-11 18:41:17 +02:00
There are several ways to use Face-API:
2020-09-09 15:29:24 +02:00
2020-10-11 18:41:17 +02:00
### IIFE script
*Size: 936KB minified*
2020-08-27 14:58:00 +02:00
2020-10-11 18:41:17 +02:00
This is simplest way for usage within Browser as it includes full version of TensorFlow/JS prepackaged with no external dependencies.
Simply include this in your `HTML` file and it's ready to use.
2020-08-27 14:58:00 +02:00
2020-10-11 18:41:17 +02:00
```html
< script src = "dist/face-api.js" > < s c r i p t >
```
2020-08-27 14:58:00 +02:00
2020-10-11 18:41:17 +02:00
IIFE script auto-registers global namespace `faceapi` within Window object.
And if you want to access `TensorFlow/JS` classes directly, they are exported as `faceapi.tf`
2020-09-01 15:28:44 +02:00
2020-10-11 18:41:17 +02:00
Pre-packaged version of `TFJS` is **2.6.0**
2020-09-01 15:28:44 +02:00
2020-10-11 18:41:17 +02:00
### ESM module
*Size: 164KB non-minified*
2020-08-27 14:58:00 +02:00
2020-10-11 18:41:17 +02:00
If you're using bundler *(such as rollup, webpack, esbuild)* to package your client application, you can import ESM version of FaceAPI which supports full tree shaking
Note that this version does NOT pre-package `TFJS` , so you'll need to include it before you import `FaceAPI`
You can use any version of `TFJS` 2.0+
2020-08-26 00:24:48 +02:00
2020-10-11 18:41:17 +02:00
```js
import * as tf from 'https://cdnjs.cloudflare.com/ajax/libs/tensorflow/2.6.0/tf.min.js'; // load directly from CDN
import * as faceapi from 'dist/face-api.esm.js';
```
*Experimental* :
You could use same syntax within your main `JS` file if it's imported with `<script type="module">`
2020-08-31 00:45:06 +02:00
2020-10-11 18:41:17 +02:00
```html
< script src = "tf.min.js" >
< script src = "./index.js" type = "module" >
```
and then in `index.js`
2020-08-31 00:45:06 +02:00
2020-10-11 18:41:17 +02:00
```js
import * as tf from 'https://cdnjs.cloudflare.com/ajax/libs/tensorflow/2.6.0/tf.min.js'; // load directly from CDN
import * as faceapi from 'dist/face-api.esm.js';
```
2020-09-01 15:28:44 +02:00
2020-10-11 18:41:17 +02:00
### NPM module
*Size: 45,104KB unpacked (including sources and pre-trained model weights)*
Simmilar to ESM module, but with full sources as it points to `build/src/index.js` instead
Recommended for NodeJS projects
Install with:
```shell
npm install @tensorflow/tfjs @vladmandic/face -api
```
And then use with:
```js
import * as tf from '@tensorflow/tfjs';
import * as faceapi from '@vladmandic/face-api';
```
2020-09-01 15:28:44 +02:00
2020-08-26 00:24:48 +02:00
## Weights
2020-08-27 15:17:39 +02:00
Pretrained models and their weights are includes in `./model` .
2020-08-18 14:01:56 +02:00
## Build
2020-10-11 18:41:17 +02:00
If you want to do a full rebuild, either download npm module
```shell
npm install @vladmandic/face -api
cd node_modules/@vladmandic/face-api
```
2020-08-31 00:45:06 +02:00
2020-10-11 18:41:17 +02:00
or clone a git project
```shell
git clone https://github.com/vladmandic/face-api
cd face-api
```
2020-08-18 14:01:56 +02:00
2020-10-11 18:41:17 +02:00
Then install all dependencies and run rebuild:
2020-08-18 14:01:56 +02:00
```shell
2020-10-11 18:41:17 +02:00
npm install
2020-08-18 14:01:56 +02:00
npm run build
```
2020-10-11 18:41:17 +02:00
Which will compile everything in `./src` into `./build` and create both ESM (standard) and IIFE (minified) bundles as well as sourcemaps in `./dist`
2020-08-18 13:54:53 +02:00
## Documentation
2020-08-27 14:58:00 +02:00
For documentation refer to original project at < https: / / github . com / justadudewhohacks / face-api . js >
## Example
Single new example that uses both models as well as all of the extensions is included in `/example/index.html`
2020-08-27 15:19:03 +02:00
Example can be accessed directly using Git pages using URL: < https: / / vladmandic . github . io / face-api / example / >
2020-08-27 14:58:00 +02:00
2020-09-09 15:29:24 +02:00
*Note: Photos shown below are taken by me*
2020-08-27 14:58:00 +02:00
