Phi*_*ler 5 object-detection tensorflow.js
我想知道如何格式化executeAsync张量流对象检测executeAsync方法输出,使其看起来像这样:
我当前的输出如下所示,仅通过浏览无法阅读:
我一直在浏览coco-ssd.js,但由于某种原因它写得很糟糕。 https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd 当然这需要美化,但是之后,几乎没有一个变量被它的名字所调用,它基本上是所有字母字母表。
这就是我得到预测的方式(未格式化):
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();
Run Code Online (Sandbox Code Playgroud)
感谢帮助。我确信还有其他人在使用 coco ssd 训练自定义模型时遇到问题。谢谢!
您正在执行自己的模型,因此需要以人类可读的方式格式化输出。如果您使用的是 tfjs 模型 coco-ssd ( https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd ),您将获得开箱即用的格式。关于你所说的written terribly,这是因为js的缩小。
回到最初的问题:如何格式化输出?查看控制台中打印的内容,我们可以看到它是一个张量。所以如果你想打印它,你首先需要下载它的数据:
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);
})
Run Code Online (Sandbox Code Playgroud)