human/test/test-node-wasm.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-09-13 19:28:35 +02:00
const tf = require('@tensorflow/tfjs'); // wasm backend requires tfjs to be loaded first
const wasm = require('@tensorflow/tfjs-backend-wasm'); // wasm backend does not get auto-loaded in nodejs
const { Canvas, Image } = require('canvas');
const Human = require('../dist/human.node-wasm.js');
2021-04-14 18:53:00 +02:00
const test = require('./test-main.js').test;
// @ts-ignore
2021-09-23 01:27:12 +02:00
Human.env.Canvas = Canvas; // requires monkey-patch as wasm does not have tf.browser namespace
// @ts-ignore
2021-09-23 01:27:12 +02:00
Human.env.Image = Image; // requires monkey-patch as wasm does not have tf.browser namespace
2021-09-13 19:28:35 +02:00
2021-04-14 18:53:00 +02:00
const config = {
cacheSensitivity: 0,
2021-09-13 19:28:35 +02:00
modelBasePath: 'https://vladmandic.github.io/human/models/',
2021-04-14 18:53:00 +02:00
backend: 'wasm',
2022-06-08 14:52:19 +02:00
wasmPath: 'node_modules/@tensorflow/tfjs-backend-wasm/dist/',
// wasmPath: `cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tf.version_core}/dist/`,
2021-04-14 18:53:00 +02:00
debug: false,
async: false,
face: {
enabled: true,
2021-09-19 20:07:53 +02:00
detector: { rotation: false },
2021-04-14 18:53:00 +02:00
mesh: { enabled: true },
iris: { enabled: true },
description: { enabled: true },
emotion: { enabled: true },
antispoof: { enabled: true },
liveness: { enabled: true },
2021-04-14 18:53:00 +02:00
},
hand: { enabled: true, rotation: false },
2021-04-14 18:53:00 +02:00
body: { enabled: true },
2021-09-20 15:42:34 +02:00
object: { enabled: true },
2021-06-05 23:51:46 +02:00
segmentation: { enabled: true },
filter: { enabled: false },
2021-04-14 18:53:00 +02:00
};
2021-09-13 19:28:35 +02:00
async function main() {
wasm.setWasmPaths(config.wasmPath);
await tf.setBackend('wasm');
await tf.ready();
test(Human.Human, config);
}
2021-09-13 19:28:35 +02:00
main();