formating tensorflowjs object detection executeAsync output to human reabale

梦想的初衷 提交于 2021-01-06 07:22:24

问题


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

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

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!


回答1:


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);
    })


来源:https://stackoverflow.com/questions/62562122/formating-tensorflowjs-object-detection-executeasync-output-to-human-reabale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!