I am working on object detection using Tensorflow.js. I am trying to run custom object detection tensorflow.js model in a browser. I could able to convert tensorflow model to tensorflow.js model (in google colab) using the following command:
!tensorflowjs_converter \
--input_format=tf_frozen_model \
--output_node_names='detection_boxes,detection_scores,detection_classes,num_detections' \
/content/frozen_inference_graph.pb \
/content/web_model
I am sharing the code snippet of inference.html file [Updated]:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script>
<!--<script src="webcam.js"></script>-->
<img id="img" src="257.jpg" width="300" height="300"/>
</head>
<body>
<button type="button" id="startPredicting" onclick="startPredicting()" >Start Predicting</button>
<button type="button" id="stopPredicting" onclick="stopPredicting()" >Stop Predicting</button>
<div id="prediction"></div>
</body>
<script src="index.js"></script>
</html>
The code snippet of index.js file is as follow [Updated]:
let model;
let isPredicting = false;
async function init(){
try {
model = await tf.loadGraphModel('http://127.0.0.1:8887/uno_model/model.json');
} catch (err) {
console.log(err);
}
}
async function predict() {
console.log("executing model");
const img = document.getElementById('img');
tf_img = tf.browser.fromPixels(img);
tf.print(tf_img)
tf_img = tf_img.expandDims(0);
console.log(tf_img.shape) // Image dimension is [1, 300, 300, 3]
let output = await model.executeAsync(
{ 'image_tensor' : tf_img},
[ 'detection_boxes','detection_scores','detection_classes','num_detections']);
for (let i = 0; i < output.length; i++){
console.log(output[i].dataSync())
}
}
init()
function startPredicting(){
isPredicting = true;
predict();
}
function stopPredicting(){
isPredicting = false;
predict();
}
It produces following output [Updated]:

I looked at the above output but I couldn't get class labels etc. How can I extract detection_classes, detection_scores, and detection_boxes? This model works properly with python code.
[Updated]: It seems like, I am getting the output after providing [1,300,300,3] image as input to the model.
Could you please guide me? Am I missing something?