【问题标题】:How to interpret tensorflowjs predict results如何解释 tensorflowjs 预测结果
【发布时间】:2021-03-08 11:28:53
【问题描述】:

我正在尝试将我的图像分类模型公开到我的 github 页面。

在python中,运行model.predict后,我曾经接收到给定图像的概率。在 tensorflowjs 上,我收到一个张量,但我不知道如何解释该数据:

js代码:

  img1.onload = function() { 
    const imageTensor = tf.browser.fromPixels(img1);  
    const smalImg = tf.image.resizeBilinear(imageTensor, [150, 150]);
    const resized = tf.cast(smalImg, 'float32');
    const t4d = tf.tensor4d(Array.from(resized.dataSync()),[1,150,150,3])

    //const preprocessedInput = imageTensor.expandDims();
      
    const prediction = model.predict(t4d);
    predicted.innerHTML = prediction.shape;
    console.log(prediction);
  }

输出:

t {kept: false, isDisposedInternal: false, shape: Array(2), dtype: "float32", size: 1, …}
dataId: {}
dtype: "float32"
id: 48
isDisposed: (...)
isDisposedInternal: false
kept: false
rank: (...)
rankType: "2"
scopeId: 9
shape: (2) [1, 1]
size: 1
strides: [1]
__proto__: Object

这是我的 github 页面:https://ramonmedeiros.github.io/cat_dog_classifier/ 这是我的模型:https://github.com/ramonmedeiros/cat_dog_classifier/blob/main/hello.py

【问题讨论】:

    标签: python tensorflow tensor tensorflow.js


    【解决方案1】:

    prediction 是一个 tensor 对象。因此,如果您想获取张量的值,可以使用prediction.dataSync() 或其异步对应物prediction.data()

    【讨论】:

      猜你喜欢
      • 2011-12-08
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      相关资源
      最近更新 更多