问题
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