face-api/README.md

109 lines
3.8 KiB
Markdown
Raw Normal View History

2020-08-18 13:54:53 +02:00
# FaceAPI
2020-08-27 14:58:00 +02:00
## Note
This is updated **face-api.js** with latest available tensorflow/js as original face-api.js is not compatible with **tfjs 2.0+**.
If original repository is updated, this one will become obsolete.
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
- Modified to make compatible with TensorFlow/JS 2.0+
2020-08-22 18:13:02 +02:00
- Trivial code changes for updated TypeScript type checking
- Removed unnecesary package dependencies (karma, jasmine, etc.)
- Updated Typescript build process to target ES2018 instead of dual ES5/ES6
2020-08-18 13:54:53 +02:00
- Changed browser bundle process to use ESBuild instead of Rollup
2020-09-03 15:07:10 +02:00
- Updated 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-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-09-09 15:29:24 +02:00
**Imporant!**: This version of **face-api** does not embedd full version of **TensorFlow/JS (tfjs)** to keep package as small as possible (322KB minified), enable dynamic loading of different tfjs backends as well as to enable reusability of tfjs for different purposes.
2020-09-03 15:07:10 +02:00
*Load tfjs explicitly before loading face-api.*
2020-09-09 15:29:24 +02:00
*Note: package `@tensorflow/tfjs` is bundle, if you want to keep your project small, import `@tensorflow/tfjs-core` plus a specific backend such as `@tensorflow/tfjs-backend-cpu`, `@tensorflow/tfjs-backend-webgl` or `@tensorflow/tfjs-node`*
2020-08-27 14:58:00 +02:00
2020-08-31 00:45:06 +02:00
For example as a script:
2020-08-27 14:58:00 +02:00
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/tensorflow/2.3.0/tf.es2017.js"></script>
<script src="/dist/face-api.js"></script> <!-- full version / 960KB -->
2020-09-03 15:07:10 +02:00
or
2020-08-27 14:58:00 +02:00
<script src="/dist/face-api.min.js"></script> <!-- minified version / 320KB -->
```
2020-09-01 15:28:44 +02:00
Or install a module:
```bash
npm install @tensorflow/tfjs @vladmandic/face-api
```
Use module using `require` (recommended for VanillaJS):
2020-08-27 14:58:00 +02:00
```js
const tf = require('@tensorflow/tfjs');
const faceapi = require('@vladmandic/face-api');
```
2020-08-26 00:24:48 +02:00
2020-09-01 15:28:44 +02:00
Use module in a JavaScript project using `import`:
2020-08-31 00:45:06 +02:00
(NodeJS requires `"type": "module"` inside `package.json` to support `import` statements)
```js
import tf from '@tensorflow/tfjs';
import faceapi from '@vladmandic/face-api';
```
2020-09-01 15:28:44 +02:00
Use module in a TypeScript project:
(TSC will compile this to `require` statements)
```js
import * as tf from '@tensorflow/tfjs';
import * as faceapi from '@vladmandic/face-api';
```
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-08-31 00:45:06 +02:00
Included in `./dist` are:
2020-08-31 15:12:04 +02:00
- face-api.cjs: CJS format, used by NodeJS import/require (default for node and browser require/import)
2020-09-01 15:28:44 +02:00
- face-api.ejs: ESM format, used by Browser (provided as an alternative)
2020-08-31 15:12:04 +02:00
- face-api.js: IIFE format, used by Browser (default for browser script)
2020-08-31 00:45:06 +02:00
- face-api.min.js: Minified IIFE format, used by Browser
2020-09-03 15:07:10 +02:00
If you want to do a full rebuild use:
2020-08-18 14:01:56 +02:00
```shell
npm run build
```
2020-08-22 18:13:02 +02:00
Which will compile everything in `./src` into `./build` and create both standard and minified bundles as well as a sourcemap 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
![alt text](example/screenshot.png)