【发布时间】: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