2022-08-15 17:29:56 +02:00
|
|
|
const log = require('@vladmandic/pilogger');
|
2022-10-17 16:47:20 +02:00
|
|
|
const tf = require('@tensorflow/tfjs-core'); // wasm backend requires tfjs to be loaded first
|
|
|
|
require('@tensorflow/tfjs-converter');
|
2021-09-13 19:28:35 +02:00
|
|
|
const wasm = require('@tensorflow/tfjs-backend-wasm'); // wasm backend does not get auto-loaded in nodejs
|
2022-08-20 15:38:08 +02:00
|
|
|
const { Canvas, Image } = require('canvas'); // eslint-disable-line node/no-extraneous-require, node/no-missing-require
|
2022-08-15 17:29:56 +02:00
|
|
|
const H = require('../dist/human.node-wasm.js');
|
2022-10-09 20:34:58 +02:00
|
|
|
const test = require('./test-node-main.js');
|
2021-04-14 18:53:00 +02:00
|
|
|
|
2022-08-15 17:29:56 +02:00
|
|
|
H.env.Canvas = Canvas; // requires monkey-patch as wasm does not have tf.browser namespace
|
|
|
|
H.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 = {
|
2024-09-11 18:13:03 +02:00
|
|
|
cacheSensitivity: 0.01,
|
2022-10-02 21:09:00 +02:00
|
|
|
modelBasePath: 'https://vladmandic.github.io/human-models/models/',
|
2021-04-14 18:53:00 +02:00
|
|
|
backend: 'wasm',
|
2022-08-15 17:29:56 +02:00
|
|
|
// wasmPath: 'node_modules/@tensorflow/tfjs-backend-wasm/dist/',
|
|
|
|
wasmPath: `https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-wasm@${tf.version_core}/dist/`,
|
2021-04-14 18:53:00 +02:00
|
|
|
debug: false,
|
|
|
|
async: false,
|
2022-08-30 16:28:33 +02:00
|
|
|
softwareKernels: true,
|
2021-04-14 18:53:00 +02:00
|
|
|
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 },
|
2021-11-09 20:37:50 +01:00
|
|
|
antispoof: { enabled: true },
|
|
|
|
liveness: { enabled: true },
|
2021-04-14 18:53:00 +02:00
|
|
|
},
|
2021-09-13 00:37:06 +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 },
|
2022-10-02 21:09:00 +02:00
|
|
|
segmentation: { enabled: false },
|
2021-06-05 23:51:46 +02:00
|
|
|
filter: { enabled: false },
|
2021-04-14 18:53:00 +02:00
|
|
|
};
|
|
|
|
|
2021-09-13 19:28:35 +02:00
|
|
|
async function main() {
|
2022-10-09 20:34:58 +02:00
|
|
|
wasm.setWasmPaths(config.wasmPath, true);
|
|
|
|
const ok = await tf.setBackend('wasm');
|
|
|
|
if (!ok) {
|
|
|
|
test.log('error', 'failed: setwasmpath', config.wasmPath);
|
|
|
|
return;
|
|
|
|
}
|
2021-09-13 19:28:35 +02:00
|
|
|
await tf.ready();
|
2022-08-15 17:29:56 +02:00
|
|
|
H.env.updateBackend();
|
2022-09-19 16:46:11 +02:00
|
|
|
log.info(H.env.wasm, config.wasmPath);
|
2022-10-09 20:34:58 +02:00
|
|
|
test.test(H.Human, config);
|
2021-09-13 19:28:35 +02:00
|
|
|
}
|
2021-09-13 00:37:06 +02:00
|
|
|
|
2022-08-30 16:28:33 +02:00
|
|
|
if (require.main === module) main();
|