I've trained my model in python and then converted the model so I could use it on my JS website. I have a brain tumor dataset, it has 4 classes:
- Glioma
- Menengioma
- No tumor
- Pituitary
So far I've done this:
<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
Which gives me an alert like [x, y, z, k]. And also I've created a .js file with classes target:
TARGET_CLASSES_BRAIN = {
0: "Glioma",
1: "Menengioma",
2: "No Tumor",
3: "Pituitary"
}
So, the thing I want to do is to have an output like:
Glioma: 0.001
Menengioma: 0.0004
No tumor: 0.99
Pituitary: 0.0086
I want to include both class names and confidence values. I'm new to the TensorflowJS, could you please direct me? Thank you so much in advance.
UPDATE: I also used a softmax
function:
Dense(4, activation='softmax')