首页 > 解决方案 > tfjs mode.predict 返回相同的结果

问题描述

我有一个在浏览器上运行的网络模型。确实面部检测的问题是随机预测开始每次都返回所有乱码结果或相同的结果。

我有时观察到它tf.browser.fromPixels似乎返回一个全零张量。我已经检查过了frame,它似乎是有效的。

关于可能发生的事情的任何想法。

      const pixels = tf.browser.fromPixels(frame).toFloat();
  const shape = pixels.reshape([-1, 104, 104, 3]);

  const tfResponse: any = this.model.predict(shape);
  tfResponse.data().then((r) => {

    try {

      if ( this.lastResponse ) {
        if ( UtilService.arraysEqual(r, this.lastResponse )) {
          throw new Error('Prediction failure start');
        }
      }
      this.lastResponse = r;
      shape.dispose();

      const detections: Array<Box> = this.parseDetectionResult(r);

      if (detections.length > 0) {

        resolve({resized: frame, face: detections});

      } else {

        reject('No face found.');

      }

    } catch (e) {
      console.log(e);
    }


  })

HTML

<app-camera-overlay _ngcontent-c8="" style="position: absolute; width: 100%; height: 100%" _nghost-c11="">
  <canvas _ngcontent-c11="" class="abs-center" id="mask-overlay" style="width: 640px; height: 360px;" width="640" height="360"></canvas>
</app-camera-overlay>

通常它的pixels似乎充满了零。

任何帮助将不胜感激,谢谢。

标签: javascripttensorflowtensorflow.js

解决方案


推荐阅读