updated node-multiprocess demo
parent
e496c9789f
commit
47cb1aac88
|
@ -30,10 +30,10 @@ async function detect(img) {
|
||||||
const tensor = await image(img);
|
const tensor = await image(img);
|
||||||
const result = await faceapi
|
const result = await faceapi
|
||||||
.detectAllFaces(tensor, optionsSSDMobileNet)
|
.detectAllFaces(tensor, optionsSSDMobileNet)
|
||||||
.withFaceLandmarks()
|
.withFaceLandmarks();
|
||||||
.withFaceExpressions()
|
// .withFaceExpressions()
|
||||||
.withFaceDescriptors()
|
// .withFaceDescriptors()
|
||||||
.withAgeAndGender();
|
// .withAgeAndGender();
|
||||||
process.send({ image: img, detected: result }); // send results back to main
|
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
|
process.send({ ready: true }); // send signal back to main that this worker is now idle and ready for next image
|
||||||
tensor.dispose();
|
tensor.dispose();
|
||||||
|
|
|
@ -8,7 +8,7 @@ const child_process = require('child_process');
|
||||||
// note that main process import faceapi or tfjs at all
|
// note that main process import faceapi or tfjs at all
|
||||||
|
|
||||||
const imgPathRoot = './demo'; // modify to include your sample images
|
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 workers = []; // this holds worker processes
|
||||||
const images = []; // this holds queue of enumerated images
|
const images = []; // this holds queue of enumerated images
|
||||||
const t = []; // timers
|
const t = []; // timers
|
||||||
|
@ -33,7 +33,7 @@ function waitCompletion() {
|
||||||
if (activeWorkers > 0) setImmediate(() => waitCompletion());
|
if (activeWorkers > 0) setImmediate(() => waitCompletion());
|
||||||
else {
|
else {
|
||||||
t[1] = process.hrtime.bigint();
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue