我用python训练了我的模型,然后对模型进行了转换,以便在我的JS网站上使用它。我有一个脑瘤数据集,它有四个类别:
到目前为止我已经这样做了:
<script>
async function LoadModels(){
model = undefined;
model = await tf.loadLayersModel("http://127.0.0.1:5500/modelsBrain/modelBrain.json");
const pr = document.getElementById('photo');
const image = tf.browser.fromPixels(pr);
const image2 = tf.reshape(image, [1,200,200,3]);
const prediction = model.predict(image2);
alert(prediction.dataSync());
}
LoadModels();
</script>
// just predicting one photo这给了我一个像x,y,z,k这样的警告。我还创建了一个带有类目标的.js文件:
TARGET_CLASSES_BRAIN = {
0: "Glioma",
1: "Menengioma",
2: "No Tumor",
3: "Pituitary"
} 所以,我想要做的是有一个输出,比如:
胶质瘤:0.001
Menengioma:0.0004
无肿瘤:0.99
垂体:0.0086
我想包括类名和信任值。我是TensorflowJS的新手,你能指点我吗?提前谢谢你。
更新:我还使用了一个softmax函数:
Dense(4, activation='softmax')发布于 2022-06-09 13:40:37
下面是一个可以帮助获取预测标签的片段
const label = ['Glioma', 'Menengioma', 'No Tumor', 'Pituitary',]
// the code for prediction
const prediction = model.predict(image2);
const listIndexes = prediction.argMax(1).dataSync(); // get the class of highest probability
labelsPred = Array.from(listIndexes ).map(index => label[index])
console.log(labelsPred)https://stackoverflow.com/questions/72535315
复制相似问题