【问题标题】:How to get label and confidence value from model.executeAsync() tensorflow如何从 model.executeAsync() tensorflow 获取标签和置信度值
【发布时间】:2020-10-15 08:00:22
【问题描述】:

我设法将我的模型转换为 model.JSON 并设法使用 model.executeAsync() 加载它。那么我如何访问输出以获取标签和置信度值以显示它。 model.executeAsync() 给我回一堆数组值

这是我的 index.js

async function init(){
try {
        model = await 
        tf.loadGraphModel('http://localhost/demo7/model/model.json');
    } catch (err) {
        console.log(err);
    }}

async function predict() {
    console.log("executing model");
    let user_pic = document.querySelector('img');
model.executeAsync(tf.browser.fromPixels(user_pic).cast('int32').expandDims())
console.log('This is your model: ', model, 'This is your prediction: ', prediction) }}
init()

结果: sample result

[[PromiseResult]]: 数组(7) 0:e 数据ID:{} 数据类型:“float32” 编号:3350 isDisposedInternal: 假 保留:假 等级类型:“3” 范围标识:6152 形状:(3) [1, 300, 4] 尺寸:1200 步幅:(2) [1200, 4] 已处置:(...) 等级:(...) 原型:对象 1:e 数据ID:{} 数据类型:“float32” 编号:3372 isDisposedInternal: 假 保留:假 排名类型:“1” 范围标识:6193 形状:1 尺寸:1 步幅:[] 已处置:(...) 等级:(...) 原型:对象 2:e 数据ID:{} 数据类型:“float32” 编号:3367 isDisposedInternal: 假 保留:假 排名类型:“2” 范围标识:6182 形状:(2) [1, 300] 尺寸:300 步幅:[300] 已处置:(...) 等级:(...) 原型:对象 3:e 数据ID:{} 数据类型:“float32” 编号:2254 isDisposedInternal: 假 保留:假 等级类型:“3” 范围标识:3543 形状:(3) [1, 300, 8] 尺寸:2400 步幅:(2) [2400, 8] 已处置:(...) 等级:(...) 原型:对象

【问题讨论】:

  • 您能否添加代码的相关部分以输出图片中的内容?顺便说一句,添加代码比添加图像更好,因为人们可以复制您拥有的内容并自行尝试。
  • 嗨,我已经用示例代码编辑了这个问题。这是我第一次顺便问,所以不太熟悉如何包含代码等。对不起

标签: tensorflow object-detection tensorflow.js


【解决方案1】:

为了得到你需要的预测

const prediction = await model.executeAsync(tf.browser.fromPixels(user_pic).cast('int32').expandDims());

【讨论】:

  • 谢谢。那么我怎样才能从该代码的输出中访问自信的值和类呢?
  • prediction 的值是多少?也许您可以使用console.log(prediction) 的输出来编辑您的问题
猜你喜欢
  • 1970-01-01
  • 2013-10-22
  • 2017-08-19
  • 1970-01-01
  • 1970-01-01
  • 2013-10-29
  • 2022-12-20
  • 2021-07-20
  • 2022-11-24
相关资源
最近更新 更多