tfjs mode.predict返回相同的结果

时间:2019-04-10 07:12:30

标签: javascript tensorflow tensorflow.js

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

我观察到有时它的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似乎充满了零。

谢谢您的任何帮助。

0 个答案:

没有答案