【发布时间】:2020-11-02 09:14:02
【问题描述】:
我正在尝试将 blazeface 模型添加到我的应用程序中。我刚刚发现当我使用WebGL后端时,第一次调用estimateFaces()
console.log("estimate started")
const predictions = await model.estimateFaces(
this.refVideo.current,
returnTensors,
flipHorizontal,
annotateBoxes
);
console.log("estimate finished") // first time it is very slow with WebGL
大约需要 18 秒。 WASM 或 CPU 后端并非如此。您还可以通过blazeface demo 感受不同之处。从右上角的菜单中将后端设置为 WebGL,然后打开您的 cam。面部检测的第一个掩码加载方式比使用 WASM 或 cpu 后端要晚得多。你知道为什么会这样吗?
张量如下:
if (predictions.length > 0) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < predictions.length; i++) {
if (returnTensors) {
predictions[i].topLeft = predictions[i].topLeft.arraySync();
predictions[i].bottomRight = predictions[i].bottomRight.arraySync();
if (annotateBoxes) {
predictions[i].landmarks = predictions[i].landmarks.arraySync();
}
}
try {
} catch (err) {
console.log(err.message);
}
this.portraitMode = false;
if (videoWidth < videoHeight && window.matchMedia("(orientation: portrait)").matches) {
this.portraitMode = true;
}
drawRoiOnCanvas(canvas, ctx, predictions[i], this.portraitMode, this.setDisableButtons)
}
}
requestAnimationFrame(this.renderPrediction);
}
};
【问题讨论】:
-
也许问题在于张量是如何传递给模型的。你能说明你是怎么做的吗?
-
当然,我编辑了问题。
-
你在使用 React Native 吗?
-
我正在使用 reactjs
标签: tensorflow webgl tensorflow.js