updated node-multiprocess demo

pull/54/head
Vladimir Mandic 2021-04-16 08:30:15 -04:00
parent e496c9789f
commit 47cb1aac88
2 changed files with 6 additions and 6 deletions

View File

@ -30,10 +30,10 @@ async function detect(img) {
const tensor = await image(img);
const result = await faceapi
.detectAllFaces(tensor, optionsSSDMobileNet)
.withFaceLandmarks()
.withFaceExpressions()
.withFaceDescriptors()
.withAgeAndGender();
.withFaceLandmarks();
// .withFaceExpressions()
// .withFaceDescriptors()
// .withAgeAndGender();
process.send({ image: img, detected: result }); // send results back to main
process.send({ ready: true }); // send signal back to main that this worker is now idle and ready for next image
tensor.dispose();

View File

@ -8,7 +8,7 @@ const child_process = require('child_process');
// note that main process import faceapi or tfjs at all
const imgPathRoot = './demo'; // modify to include your sample images
const numWorkers = 2; // how many workers will be started
const numWorkers = 4; // how many workers will be started
const workers = []; // this holds worker processes
const images = []; // this holds queue of enumerated images
const t = []; // timers
@ -33,7 +33,7 @@ function waitCompletion() {
if (activeWorkers > 0) setImmediate(() => waitCompletion());
else {
t[1] = process.hrtime.bigint();
log.info('Processed', numImages, 'images in', Math.trunc(parseInt(t[1] - t[0]) / 1000 / 1000), 'ms');
log.info('Processed:', numImages, 'images in', 'total:', Math.trunc(parseInt(t[1] - t[0]) / 1000000), 'ms', 'working:', Math.trunc(parseInt(t[1] - t[2]) / 1000000), 'ms', 'average:', Math.trunc(parseInt(t[1] - t[2]) / numImages / 1000000), 'ms');
}
}