Распознавание изображений с использованием Tensorflow.js - PullRequest
0 голосов
/ 28 июня 2018

Я новичок в ML и пытаюсь распознать изображение с помощью своей мобильной камеры и предварительно обученной модели с помощью Tensorflow.js. Я использовал пример pacman на сайте Tensorflow.js и изменил его.

Вот некоторые из соответствующих кодов:

async loadModel() {
  console.log('Loading model...');
  const startTime = performance.now();
  this.model = await loadFrozenModel(MODEL_URL, WEIGHTS_URL);
  const totalTime = Math.floor(performance.now() - startTime);
  console.log(`Model loaded and initialized in ${totalTime}ms...`);
  this.setup(); // Opens the camera and pass the video stream source to the video element
}

Это загрузит модель, которую я конвертировал с использованием tenorflowjs-converter . После загрузки модели я открываю камеру, используя navigator.getUserMedia, и назначаю источник потока для видеоэлемента HTML, который я создал в HTML. Сейчас. После того, как камера открыта, я вызываю следующий метод прогнозирования:

  async predict() {
    while (this.isPredicting) {
      console.log("predicting . . . . . . . . ");
      const predictionData = tf.tidy(() => {
        // Capture the frame from the webcam.
        const img = this.capture();
        const predictions = this.model.predict(img);

        // Returns the index with the maximum probability. This number corresponds
        // to the class the model thinks is the most probable given the input.
        return predictions;
      });

      const classId = (await predictionData.data());
      console.log(classId);
      predictionData.dispose();
      await tf.nextFrame();
    }
}

console.log(classId) регистрируется под объектом независимо от положения камеры.

Float32Array(2) [0.0467529296875, 0.953125]

Может кто-нибудь помочь мне понять ошибку здесь, пожалуйста?

...