Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@vladmandic/face-api
Advanced tools
JavaScript module for Face Detection and Face Recognition Using Tensorflow/JS
This is updated face-api.js with latest available TensorFlow/JS as the original face-api.js is not compatible with tfjs 2.0+.
Forked from face-api.js version 0.22.2 released on March 22nd, 2020
Currently based on TensorFlow/JS
2.8.0
Because I needed Face-API that does not cause version conflict with newer TFJS 2.0 that I use accross my projects
And since original Face-API was open-source, I've released this version as well
Unfortunately, changes ended up being too large for a simple pull request on original Face-API and it ended up being a full-fledged version on its own
TensorFlow/JS 2.0+
WebGL
, CPU
and WASM
TFJS Browser backendstfjs-node
and tfjs-node-gpu
TFJS NodeJS backendsTypeScript 4.1
UMD
to ESM
+ CommonJS
with fallback to IIFE
ESM
moduleESBuild
instead of Rollup
ES2018
and instead of dual ES5/ES6karma
, jasmine
, babel
, etc.)@tensorflow/tfjs-core
batchNorm()
dependencyversion
class that returns JSON object with version of FaceAPI as well as linked TFJSmtcnn
and tinyYolov2
models as they were non-functional in latest public version of Face-API
Which means valid models are tinyFaceDetector and mobileNetv1
Browser example that uses both models as well as all of the extensions is included in /example/index.html
Example can be accessed directly using Git pages using URL: https://vladmandic.github.io/face-api/example/
Note: Photos shown below are taken by me
Two NodeJS examples are:
/example/node-singleprocess.js
: Regular usage of FaceAPI
from NodeJS
/example/node-multiprocess.js
: Multiprocessing showcase that uses pool of worker processes (node-multiprocess-worker.js
Main starts fixed pool of worker processes with each worker having it's instance of FaceAPI
2020-12-08 08:30:01 INFO: @vladmandic/face-api version 0.9.1
2020-12-08 08:30:01 INFO: User: vlado Platform: linux Arch: x64 Node: v15.0.1
2020-12-08 08:30:01 INFO: FaceAPI multi-process test
2020-12-08 08:30:01 STATE: Main: started worker: 265238
2020-12-08 08:30:01 STATE: Main: started worker: 265244
2020-12-08 08:30:02 STATE: Worker: PID: 265238 TensorFlow/JS 2.7.0 FaceAPI 0.9.1 Backend: tensorflow
2020-12-08 08:30:02 STATE: Worker: PID: 265244 TensorFlow/JS 2.7.0 FaceAPI 0.9.1 Backend: tensorflow
2020-12-08 08:30:02 STATE: Main: dispatching to worker: 265238
2020-12-08 08:30:02 STATE: Main: dispatching to worker: 265244
2020-12-08 08:30:02 DATA: Worker received message: 265238 { image: 'example/sample (1).jpg' }
2020-12-08 08:30:02 DATA: Worker received message: 265244 { image: 'example/sample (2).jpg' }
2020-12-08 08:30:04 DATA: Main: worker finished: 265238 detected faces: 3
2020-12-08 08:30:04 STATE: Main: dispatching to worker: 265238
2020-12-08 08:30:04 DATA: Main: worker finished: 265244 detected faces: 3
2020-12-08 08:30:04 STATE: Main: dispatching to worker: 265244
2020-12-08 08:30:04 DATA: Worker received message: 265238 { image: 'example/sample (3).jpg' }
2020-12-08 08:30:04 DATA: Worker received message: 265244 { image: 'example/sample (4).jpg' }
2020-12-08 08:30:06 DATA: Main: worker finished: 265238 detected faces: 3
2020-12-08 08:30:06 STATE: Main: dispatching to worker: 265238
2020-12-08 08:30:06 DATA: Worker received message: 265238 { image: 'example/sample (5).jpg' }
2020-12-08 08:30:06 DATA: Main: worker finished: 265244 detected faces: 4
2020-12-08 08:30:06 STATE: Main: dispatching to worker: 265244
2020-12-08 08:30:06 DATA: Worker received message: 265244 { image: 'example/sample (6).jpg' }
2020-12-08 08:30:07 DATA: Main: worker finished: 265238 detected faces: 5
2020-12-08 08:30:07 STATE: Main: worker exit: 265238 0
2020-12-08 08:30:08 DATA: Main: worker finished: 265244 detected faces: 4
2020-12-08 08:30:08 INFO: Processed 12 images in 6826 ms
2020-12-08 08:30:08 STATE: Main: worker exit: 265244 0
Note that @tensorflow/tfjs-node
or @tensorflow/tfjs-node-gpu
must be installed before using NodeJS example
Face-API ships with several pre-build versions of the library:
dist/face-api.js
: IIFE format for client-side Browser execution with TFJS pre-bundleddist/face-api.esm.js
: ESM format for client-side Browser execution with TFJS pre-bundleddist/face-api.esm-nobundle.js
: ESM format for client-side Browser execution without TFJS pre-bundleddist/face-api.node.js
: CommonJS format for server-side NodeJS execution without TFJS pre-bundleddist/face-api.node-gpu.js
: CommonJS format for server-side NodeJS execution without TFJS pre-bundled and optimized for CUDA GPU accelerationDefaults are:
{
"main": "dist/face-api.node-js",
"module": "dist/face-api.esm.js",
"browser": "dist/face-api.esm.js",
}
Bundled TFJS
can be used directly via export: faceapi.tf
Reason for additional nobundle
version is if you want to include a specific version of TFJS and not rely on pre-packaged one
FaceAPI
is compatible with TFJS 2.0+
All versions include sourcemap
and asset manifest
There are several ways to use Face-API:
Recommened for quick tests and backward compatibility with older Browsers that do not support ESM such as IE
This is simplest way for usage within Browser
Simply download dist/face-api.js
, include it in your HTML
file & it's ready to use
<script src="dist/face-api.js"><script>
IIFE script bundles TFJS and auto-registers global namespace faceapi
within Window object which can be accessed directly from a <script>
tag or from your JS file.
Recommended for usage within Browser
To use ESM import directly in a Browser, you must import your script (e.g. index.js
) with a type="module"
<script src="./index.js" type="module">
and then in your index.js
import * as faceapi from 'dist/face-api.esm.js';
Same as above, but expectation is that you've installed @vladmandic/faceapi
package:
npm install @vladmandic/face-api
and that you'll package your application using a bundler such as webpack
, rollup
or esbuild
in which case, you do not need to import a script as module - that depends on your bundler configuration
import * as faceapi from '@vladmandic/face-api';
or if your bundler doesn't recognize recommended
type, force usage with:
import * as faceapi from '@vladmandic/face-api/dist/face-api.esm.js';
or to use non-bundled version
import * as tf from `@tensorflow/tfjs`;
import * as faceapi from '@vladmandic/face-api/dist/face-api.esm-nobundle.js';
Recommended for NodeJS projects
Node: Face-API for NodeJS does not bundle TFJS due to binary dependencies that are installed during TFJS installation
Install with:
npm install @tensorflow/tfjs-node
npm install @vladmandic/face-api
And then use with:
const tf = require('@tensorflow/tfjs-node')
const faceapi = require('@vladmandic/face-api');
If you want to force CommonJS module instead of relying on recommended
field:
const faceapi = require('@vladmandic/face-api/dist/face-api.node.js');
If you want to GPU Accelerated execution in NodeJS, you must have CUDA libraries already installed and working
Then install appropriate version of Face-API
:
npm install @tensorflow/tfjs-node
npm install @vladmandic/face-api
And then use with:
const tf = require('@tensorflow/tfjs-node-gpu')
const faceapi = require('@vladmandic/face-api/dist/face-api.node-gpu.js'); // this loads face-api version with correct bindings for tfjs-node-gpu
Pretrained models and their weights are includes in ./model
.
If you want to do a full rebuild, either download npm module
npm install @vladmandic/face-api
cd node_modules/@vladmandic/face-api
or clone a git project
git clone https://github.com/vladmandic/face-api
cd face-api
Then install all dependencies and run rebuild:
npm install
npm run build
Build process uses script build.js
that creates optimized build for each target:
npm run build
> @vladmandic/face-api@0.8.9 build /home/vlado/dev/face-api
> rimraf dist/* && node ./build.js
2020-12-02 16:31:23 INFO: @vladmandic/face-api version 0.8.9
2020-12-02 16:31:23 INFO: User: vlado Platform: linux Arch: x64 Node: v15.0.1
2020-12-02 16:31:23 INFO: Build: file startup all target: es2018
2020-12-02 16:31:23 STATE: Build for: node type: tfjs: { imports: 1, importBytes: 39, outputBytes: 1042, outputFiles: 'dist/tfjs.esm.js' }
2020-12-02 16:31:23 STATE: Build for: node type: node: { imports: 160, importBytes: 228038, outputBytes: 134190, outputFiles: 'dist/face-api.node.js' }
2020-12-02 16:31:23 STATE: Build for: nodeGPU type: tfjs: { imports: 1, importBytes: 43, outputBytes: 1046, outputFiles: 'dist/tfjs.esm.js' }
2020-12-02 16:31:23 STATE: Build for: nodeGPU type: node: { imports: 160, importBytes: 228042, outputBytes: 134198, outputFiles: 'dist/face-api.node-gpu.js' }
2020-12-02 16:31:23 STATE: Build for: browserNoBundle type: tfjs: { imports: 1, importBytes: 1784, outputBytes: 244, outputFiles: 'dist/tfjs.esm.js' }
2020-12-02 16:31:23 STATE: Build for: browserNoBundle type: esm: { imports: 160, importBytes: 227240, outputBytes: 131024, outputFiles: 'dist/face-api.esm-nobundle.js' }
2020-12-02 16:31:24 STATE: Build for: browserBundle type: tfjs: { modules: 1045, moduleBytes: 3718721, imports: 7, importBytes: 1784, outputBytes: 1501677, outputFiles: 'dist/tfjs.esm.js' }
2020-12-02 16:31:24 STATE: Build for: browserBundle type: iife: { imports: 162, importBytes: 1728673, modules: 576, moduleBytes: 1359851, outputBytes: 1903311, outputFiles: 'dist/face-api.js' }
2020-12-02 16:31:25 STATE: Build for: browserBundle type: esm: { imports: 162, importBytes: 1728673, modules: 576, moduleBytes: 1359851, outputBytes: 1900836, outputFiles: 'dist/face-api.esm.js' }
0.9.5 2020/12/19 mandic00@live.com
FAQs
FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS
The npm package @vladmandic/face-api receives a total of 9,410 weekly downloads. As such, @vladmandic/face-api popularity was classified as popular.
We found that @vladmandic/face-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.