【问题标题】:WebGL backend for tensorflowjs loads the model (blazeface) very latetensorflowjs 的 WebGL 后端加载模型(blazeface)很晚
【发布时间】: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


【解决方案1】:

我认为这个问题与将 Blazeface 的权重加载到 GPU 所需的时间有关。我在导入 Facemesh 时遇到了同样的问题。每当我使用wasm 后端加载它然后将后端更改为webgl 时,它会延迟约5 秒才能正常工作。对我有用的是在加载 Facemesh 模型之前将后端设置为 webgl

【讨论】:

    猜你喜欢
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2023-02-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多