Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@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.6.0
If you want to access TFJS
classes and methods directly, they are exported as faceapi.tf
Because I needed FaceAPI that does not cause version conflict with newer TFJS 2.0 that I use accross my projects
And since original FaceAPI was open-source, I've released this version as well
Unfortunately, changes ended up being too large for a simple pull request on original FaceaPI and it ended up being a full-fledged version on its own
TensorFlow/JS 2.0+
WebGL
, CPU
and WASM
TFJS backendsTypeScript 4.1
UMD
to ESM
+ CommonJS
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
Face-API ships with several pre-build versions of the library:
dist/face-api.js
: IIFE format for client-side Browser exeuctiondist/face-api.esm.js
: ESM format for client-side Browser execution with TFJS pre-bundleddist/face-api.nobundle.js
: ESM format for client-side Browser execution without TFJS and not minifieddist/face-api.node.js
: CommonJS format for server-side NodeJS execution with TFJS pre-bundleddist/face-api.nobundle.js
: CommonJS format for server-side NodeJS execution without TFJS and not minifiedDefaults are:
{
"main": "dist/face-api.cjs",
"module": "dist/face-api.esm.js",
"browser": "dist/face-api.esm.js",
}
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+
Bundled versions are ~1.1MB minified and non-bundled versions are ~169KB non-minified
All versions include sourcemap
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';
or to use non-bundled version:
import * as tf from `https://cdnjs.cloudflare.com/ajax/libs/tensorflow/2.6.0/tf.es2017.min.js`; // load tfjs directly from CDN link
import * as faceapi from 'dist/face-api.nobundle.js';
Same as above, but expectation is that you've installed @vladmandic/faceapi
package
and that you'll package your script 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.nobundle.js';
Recommended for NodeJS projects
Install with:
npm install @vladmandic/face-api
And then use with:
const faceapi = require('@vladmandic/face-api');
or if you want to force CommonJS module instead of relying on recommended
field:
const faceapi = require('@vladmandic/face-api/dist/face-api.cjs');
or if you want to use a non-bundled version: Install with:
npm install @tensorflow/tfjs
npm install @vladmandic/face-api
And then use with:
const tf = require('@tensorflow/tfjs');
const faceapi = require('@vladmandic/face-api/dist/face-api.nobundle.cjs');
Recommended for complex NodeJS projects that use TFJS for other purposes and not just FaceaPI
This way you're importing FaceAPI sources directly and not a bundle, so you have to import @tensorflow/tfjs
explicitly
import * as tf from '@tensorflow/tfjs';
import * as faceapi from '@vladmandic/face-api/build/index.js';
import * as tf from '@tensorflow/tfjs';
import * as faceapi from '@vladmandic/face-api/src/index.ts';
const tf = require('@tensorflow/tfjs');
const faceapi = require('@vladmandic/face-api/build/index.js');
const tf = require('@tensorflow/tfjs');
const faceapi = require('@vladmandic/face-api/src/index.ts');
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
Which will compile everything in ./src
into ./build
and create both ESM (standard) and IIFE (minified) bundles as well as sourcemaps in ./dist
For documentation refer to original project at https://github.com/justadudewhohacks/face-api.js
For original weighs refer to https://github.com/justadudewhohacks/face-api.js-models
Single new 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
0.8.4 2020/10/27 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 8,877 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.