(EDIT: partly solved, please see the end of the post) I have successfully uploaded a custom Tensorflow.js classifier that makes predictions of my webcam feed. It's trained on two classes, "good" and "bad". I get results as an array (correct me if I'm using the terms wrong as I'm a newbie!)
As the next step, I want to print the labels and confidence values on my browser. However, I find it a bit hard to grasp how I access my "good" and "bad" labels and confidence values from this result format that I get:
const result = await model.predict(t4d);
console.log(result);
(console)
t {kept: false, isDisposedInternal: false, shape: Array(2), dtype: "float32", size: 2, …}
dataId:
__proto__: Object
dtype: "float32"
id: 685817
isDisposedInternal: false
kept: false
rankType: "2"
scopeId: 883969
shape: (2) [1, 2]
size: 2
strides: [2]
isDisposed: (...)
rank: (...)
__proto__: Object
If I understand right, it gives me shape 2 = class 2 as a result (or is it just the shape and not my class yet?). Can anybody give advice on how to manually assign labels for these shapes 1 and 2 so that they can be printed? And how would I access confidence values - with argMax?
Ideally I would want it print something like this:
Good: 0.703 Bad: 0.298
Reference is this out-of-the-box mobilenet example from Tensorflow.js tutorials:
const webcam = await tf.data.webcam(webcamElement);
while (true) {
const img = await webcam.capture();
const result = await net.classify(img);
document.getElementById('console').innerText = `
prediction: ${result[0].className}\n
probability: ${result[0].probability}
`;
Where it prints the most probable class label and confidence value (like cat, 0.3444).
Warm thanks for any help!
EDIT: By following this tutorial, I was able to extract the label by making an array of my labels:
const labels = ["good", "bad"];