face-api - Improve speed of first detection in face-api.js?
问题描述
In face-api.js the first call to detect a photo takes about 10 seconds, and then takes milliseconds for all subsequent detections.
Is there any way to call some function to prepare before starting detection and avoid this initial delay? Taking into consideration that the user needs to do an action (click a button) to start the face detection.
I am already doing the initiated boot load. According to the code.
App Init()
const MODEL_URL = "/static/models";
faceapi.loadTinyFaceDetectorModel(MODEL_URL);
await faceapi.loadFaceLandmarkTinyModel(MODEL_URL);
await faceapi.loadFaceDetectionModel(MODEL_URL);
await faceapi.loadFaceRecognitionModel(MODEL_URL);
navigator.mediaDevices
.getUserMedia({ video: { frameRate: { ideal: 10, max: 15 } } })
.then(stream => {
this.cameraPreview.srcObject = stream;
this.cameraPreview.style.display = "block";
})
.catch(err => {
alert("error");
});
Call Detect
start(){
configProcessFace();
detectFace();
}
configProcessFace() {
let inputSize = 128;
let scoreThreshold = 0.58;
this.faceOptions = new faceapi.TinyFaceDetectorOptions({
inputSize,
scoreThreshold
});
},
async detectFace() {
faceapi
.detectSingleFace(this.cameraPreview, this.faceOptions)
.run()
.then(res => {
if (res && res.box) {
...
}
window.setTimeout(() => {
this.detectFace();
}, 40);
})
.catch(err => {
console.log(err);
});
解决方案
我以 512x512 的比例推送一张带有人脸的图片,并在加载应用程序时进行了识别。当用户识别它时,它需要 1 秒。
咨询:
prepareFaceDetector() {
let base_image = new Image();
base_image.src = "/static/img/startFaceDetect.jpg";
base_image.onload = function() {
const useTinyModel = true;
const fullFaceDescription = faceapi
.detectSingleFace(base_image, new faceapi.TinyFaceDetectorOptions())
.withFaceLandmarks(useTinyModel)
.withFaceDescriptor()
.run()
.then(res => {
console.log("--------> " + JSON.stringify(res));
});
};
}
推荐阅读
- assembly - 如何阅读 WebAssembly
- python - 有没有办法根据时间戳列出 AzureBlobStorage 中的 blob?
- cron - Cronjobs 不运行
- c# - 检查源列表中是否存在多个子列表
- python - 如何将一个图的边权重添加到 NetworkX 中不同图中的匹配边?
- java - 如何对包含计划执行的方法进行单元测试?
- android - Glide 无法加载这种类型的 url 图片
- php - 在 Woocommerce 单个产品页面中显示特定产品标签的自定义内容
- r - 如何将 sf 导入包以运行依赖于 lwgeom 的函数?
- python - 将环境变量添加到主文件后单元测试失败