【问题标题】:formating tensorflowjs object detection executeAsync output to human reabale将tensorflow js对象检测executeAsync输出格式化为人类可读
【发布时间】:2020-06-24 18:50:01
【问题描述】:

我想知道如何格式化 executeAsync tensorflow 对象检测 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();

感谢您的帮助。我敢肯定还有其他人在使用 coco ssd 训练自定义模型时遇到问题。 谢谢!

【问题讨论】:

    标签: object-detection tensorflow.js


    【解决方案1】:

    您正在执行自己的模型,因此需要以人类可读的方式格式化您的输出。如果您使用的是 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);
        })
    

    【讨论】:

    • 非常感谢,这太棒了。我已经使用 coco-ssd 大约一个星期了,有许多版本的依赖项和各种操作系统的多个教程,让事情正常工作非常令人沮丧。我知道我的问题在于对 coco-ssd.js 的理解,这很令人沮丧,因为我只是无法阅读它,而是将每一行都打印出来。对于新手来说这将是惊人的,因为对于刚开始拥有一个整齐注释版本的 coco-ssd.js 的人们来说,这是一个非常有趣的话题(希望我没有错过)。
    • 也许我还没有理解整个 coco-ssd 范式,但我的理解是你必须创建自己的模型才能检测到自己的对象。在我的情况下,椅子在建筑平面图布局上。反正。因此,再次感谢您的解决方案,以防我想添加一个字符串数组: ['detection_classes', 'detection_boxes'] 它给了我一个错误,说“predictions.dataSync 不是一个函数”。我只是复制粘贴了您发送的部分,三次并每次添加一个不同的字符串,效果很好。这看起来不太好,改进的想法?
    • 也许预测是一个张量数组。如果是这种情况,您可以使用:predictions[0].dataSync() 获得第一个张量。注释代码在这里:github.com/tensorflow/tfjs-models/tree/master/coco-ssd/src
    • 你真的可以看看这个吗? stackoverflow.com/questions/62574058/… - 我猜这有点像后续行动。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 2019-11-18
    • 1970-01-01
    相关资源
    最近更新 更多