Philipp Siedler
Philipp Siedler

Reputation: 87

formating tensorflowjs object detection executeAsync output to human reabale

I'm wondering how to format the executeAsync tensorflow object detection executeAsync methods output so it look liks this:

enter image description here

My current output looks like this and is impossible to read just by browsing through:

enter image description here

I have been browsing through the coco-ssd.js, but for some reason it is written terribly. https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd of course this needs to be beautified, but after that, there is almost not a single variable called by its name, its basically the all letters in the alphabet.

This is how I get my prediction (unformated):

async function asyncCall() {
  const modelUrl = 'http://192.168.0.14:8000/web_model_4/model.json';

  const img = document.getElementById('img');
  const imgTensor = tf.browser.fromPixels(img);
  const t4d = imgTensor.expandDims(0);

  const model = await tf.loadGraphModel(modelUrl).then(model => {
    predictions = model.executeAsync(t4d, ['detection_classes']).then(predictions=> { //, 'detection_classes', 'detection_scores'
      console.log('Predictions: ', predictions);
    })
  })
}
asyncCall();

Help is appreciated. I'm sure there are others having the problem training custom models with coco ssd. Thanks!

Upvotes: 5

Views: 2297

Answers (1)

edkeveked
edkeveked

Reputation: 18401

You are executing your own model and as a result need to format your output in a way that is human readable. If you were using the tfjs model coco-ssd (https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd), you will get the formatting out of the box. Regarding what you are calling written terribly, it is because of the minification of js.

Back to the original question: how to format the output ? Looking at what is printed in the console, we can see that it is a tensor. So if you want to print it, you will first need to download its data first:

predictions = model.executeAsync(t4d, ['detection_classes']).then(predictions=> { 
      const data = predictions.dataSync() // you can also use arraySync or their equivalents async methods
      console.log('Predictions: ', data);
    })

Upvotes: 4

Related Questions