如何解释tensorflowjs预测结果

2024-09-28 23:13:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图将我的图像分类模型公开给我的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


Tags: 模型图像githubfalsemodeltf页面predict