I want to use face detection on my server-side. Therefore, I found face-api.js for this task.
I discovered that each call of faceapi.detectAllFaces()
lasts for ~10 seconds.
But when I start the browser-example, only the first function lasts 10 seconds and all the next lasts less than one second.
My server-side code (you can see a similar code in ageAndGenderRecognition.ts):
import * as faceapi from 'face-api.js';
import { canvas, faceDetectionNet, faceDetectionOptions, saveFile } from './commons';
await faceDetectionNet.loadFromDisk('../../weights')
await faceapi.nets.faceLandmark68Net.loadFromDisk('../../weights')
await faceapi.nets.ageGenderNet.loadFromDisk('../../weights')
const img = await canvas.loadImage('../images/bbt1.jpg')
console.time();
const results = await faceapi.detectAllFaces(img, faceDetectionOptions);
// ~10 seconds.
console.timeEnd();
console.time();
const results2 = await faceapi.detectAllFaces(img, faceDetectionOptions);
// ~10 seconds again.
console.timeEnd();
Why faceapi.detectAllFaces()
(except first call) is faster in browser-example than in ageAndGenderRecognition.ts? And which similar thing I can to do to my faceapi.detectAllFaces()
-function has the same speed?