打印 argMax 索引的值?
Printing the value of argMax index?
我想在这种情况下打印 argMax 索引的实际值(最高概率):
const result = await model.predict(t4d);
result.print(); // puts out: Tensor [[0.9899636, 0.0100364],]
result.as1D().argMax().print(); // prints either 0 or 1
除了索引,我还想在 argMax() 后面打印实际值 0,XXXX。有什么建议吗?
测试无效:
const confidence = result.dataSync<'float32'()>;
console.log(confidence);
对不起,如果这是一个已经回答过任何次的问题,我已经花了几个小时搜索!
argMax索引的值可以在得到tensors的数据后得到
const result = await model.predict(t4d);
const index = await result.as1D().argMax().data()[0]
const predict = await result.data()
// get the value
const value = result[index]
另一种可能是使用 topk
const topk = result.as1D().topk()
// get the highest value
value = topk.value() // the value here is a tensor
我想在这种情况下打印 argMax 索引的实际值(最高概率):
const result = await model.predict(t4d);
result.print(); // puts out: Tensor [[0.9899636, 0.0100364],]
result.as1D().argMax().print(); // prints either 0 or 1
除了索引,我还想在 argMax() 后面打印实际值 0,XXXX。有什么建议吗?
测试无效:
const confidence = result.dataSync<'float32'()>;
console.log(confidence);
对不起,如果这是一个已经回答过任何次的问题,我已经花了几个小时搜索!
argMax索引的值可以在得到tensors的数据后得到
const result = await model.predict(t4d);
const index = await result.as1D().argMax().data()[0]
const predict = await result.data()
// get the value
const value = result[index]
另一种可能是使用 topk
const topk = result.as1D().topk()
// get the highest value
value = topk.value() // the value here is a tensor