【问题标题】:TensorFlow js prediction results in the same answerTensorFlow js 预测结果相同
【发布时间】:2021-05-01 16:48:55
【问题描述】:

我通过将 python 模型转换为 tensorflow js 模型制作了一个 tensorflow js 模型。 python 模型预测图像并对其进行精细分类,但是使用 tensorflow js 模型,预测结果总是完全相同。

import * as tf from "@tensorflow/tfjs";
export default {
  data() {
    return {
      model: null,
      img: null,
      result: null,
    }
  },
  methods: {
    testModel() {
      const example = tf.browser.fromPixels(this.img)
      const prediction = this.model.predict(example.expandDims(0))
      this.result = prediction.argMax().dataSync()[0]
    }

  },
  async mounted() {
    this.model = await tf.loadLayersModel('/model.json')
    this.img = new Image()
    this.img.src = '/test_image.png'

  }
}

【问题讨论】:

  • 您是否以与 Python 脚本相同的方式预处理此测试图像?

标签: tensorflow tensorflow.js


【解决方案1】:

也许预测是在图像完成加载之前发生的。我认为图像将全是黑色像素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 2019-01-02
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    相关资源
    最近更新 更多