我正试图将我的图像分类模型公开给我的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
prediction
是一个tensor
对象。因此,如果您想获得张量的值,可以使用prediction.dataSync()
或其异步对应物prediction.data()
相关问题 更多 >
编程相关推荐