将 tensorflowjs 对象检测 executeAsync 输出格式化为人工 [英] formating tensorflowjs object detection executeAsync output to human reabale
问题描述
我想知道如何格式化 executeAsync tensorflow 对象检测 executeAsync 方法输出,使其看起来像这样:
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:
我一直在浏览 coco-ssd.js,但由于某种原因,它写得非常糟糕.https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd当然这需要美化,但在那之后,几乎没有一个变量叫它的名字,基本上是字母表中的所有字母.
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();
感谢帮助.我敢肯定还有其他人在使用 coco ssd 训练自定义模型时遇到了问题.谢谢!
Help is appreciated. I'm sure there are others having the problem training custom models with coco ssd. Thanks!
推荐答案
您正在执行自己的模型,因此需要以人类可读的方式格式化输出.如果您使用的是 tfjs 模型 coco-ssd (https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd),您将获得开箱即用的格式.关于你所说的写得很糟糕
,是因为js的缩小.
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);
})
这篇关于将 tensorflowjs 对象检测 executeAsync 输出格式化为人工的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!