【发布时间】:2020-03-03 22:58:10
【问题描述】:
我已经训练了自己的图形模型。我想在浏览器上使用它。这是我的代码:
async function predict() {
const model = await tf.loadGraphModel('./model/model.json');
let img = document.getElementById('test');
var example = tf.browser.fromPixels(img);
example = example.expandDims(0);
const output = await model.predict(example).data();
console.log(output);
}
当我运行它时,它在控制台上给出了这个错误:
Uncaught (in promise) Error: This execution contains the node 'SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/while/Exit_4', which has the dynamic op 'Exit'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs [SecondStagePostprocessor/BatchMultiClassNonMaxSuppression/map/TensorArrayStack_2/TensorArrayGatherV3]
at t.compile (tfjs:2)
at t.execute (tfjs:2)
at t.execute (tfjs:2)
at predict ((index):85)
at /websites/optik2/async http://localhost/websites/optik2/:96
我需要predict() 函数,executeAsync() 不是很好。
编辑
好的,我现在使用 executeAsync,正如 @Jason Mayes 所说。但它会返回一些类似的值:
t {kept: false, isDisposedInternal: false, shape: Array(3), dtype: "float32", size: 1200, …}
rank: 3
isDisposed: false
kept: false
isDisposedInternal: false
shape: (3) [1, 300, 4]
dtype: "float32"
size: 1200
strides: (2) [1200, 4]
dataId: {}
id: 2198
rankType: "3"
scopeId: 3545
__proto__: Object
我怎样才能得到这个的边界框?
【问题讨论】:
-
executeAsync() 有什么问题?
-
好的,我正在使用它。你知道我怎样才能从 executeAsync 获得边界框吗?这是我自己的模型
-
目前返回什么?由于它是异步的,因此您需要等待它完成才能填充输出。下面更新了答案。