如何在tensorflow.js中解释对象检测模型的输出

如何在tensorflow.js中解释对象检测模型的输出,tensorflow,tensorflow.js,Tensorflow,Tensorflow.js,我正在尝试在浏览器中运行自定义对象检测tensorflow.js模型。我可以使用以下命令将tensorflow模型转换为tensorflow.js模型(在google colab中): !tensorflowjs_converter \ --input_format=tf_frozen_model \ --output_node_names='detection_boxes,detection_scores,detection_classes,num_detections' \ /content

我正在尝试在浏览器中运行自定义对象检测tensorflow.js模型。我可以使用以下命令将tensorflow模型转换为tensorflow.js模型(在google colab中):

!tensorflowjs_converter \
--input_format=tf_frozen_model \
--output_node_names='detection_boxes,detection_scores,detection_classes,num_detections' \
/content/frozen_inference_graph.pb \
/content/web_model
我正在共享
interference.html
文件的代码片段:

<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"> </script>
<script src="webcam.js"></script>
</head>
<body>
    <div>
        <div>
            <video autoplay playsinline muted id="wc" width="224" height="224"></video>
        </div>
    </div>
    <button type="button" id="startPredicting" onclick="startPredicting()" >Start Predicting</button>
    <button type="button" id="stopPredicting" onclick="stopPredicting()" >Stop Predicting</button>
    <div id="prediction"></div>
</body>

<script src="index.js"></script>
</html>
当我使用web服务器运行上述
inference.html
文件时,它返回以下输出:

(4) [t, t, t, t]
0: t {kept: false, isDisposedInternal: false, shape: Array(3), dtype: "float32", size: 400, …}
1: t {kept: false, isDisposedInternal: false, shape: Array(2), dtype: "float32", size: 100, …}
2: t {kept: false, isDisposedInternal: false, shape: Array(2), dtype: "float32", size: 100, …}
3: t {kept: false, isDisposedInternal: false, shape: Array(1), dtype: "float32", size: 1, …}
length: 4
__proto__: Array(0)

问题是输出似乎无关紧要,或者我无法理解。我错过什么了吗?请给我你的建议。很抱歉写了这么长的帖子,但我是tensorflow的初学者。js

输出是一个tf.Tensor。当您调用
console.log(output)
时,它会尝试对对象进行字符串化并打印出其
属性

张量还有一种方法,
print
,用于注销其数据

要将数据作为javaScript数组从tensor中取出,可以调用
data
(分别
dataSync
)和
dataArray
(分别
dataArraySync
)等方法来异步(分别同步)检索数据。数据以
类型Darray
检索

output=wait model.executeAsync(img);
//输出是tf.tensor的数组。
output.forEach(t=>t.print())//注销所有张量的数据
常量数据=[]
for(设i=0;i
输出是一个tf.Tensor。当您调用
console.log(output)
时,它会尝试对对象进行字符串化并打印出其
属性

张量还有一种方法,
print
,用于注销其数据

要将数据作为javaScript数组从tensor中取出,可以调用
data
(分别
dataSync
)和
dataArray
(分别
dataArraySync
)等方法来异步(分别同步)检索数据。数据以
类型Darray
检索

output=wait model.executeAsync(img);
//输出是tf.tensor的数组。
output.forEach(t=>t.print())//注销所有张量的数据
常量数据=[]
for(设i=0;i
感谢您的回答,但使用上述建议,它会打印错误消息:
output.print不是predict的函数
index.js:21未捕获(承诺)类型错误:output.data不是predict的函数(index.js:21)
您能用
executeAsync
的定义更新您的问题吗?对不起,我没有收到您的问题。我试图使用
model.execute
但我得到了以下错误:
错误:此执行包含节点'Postprocessor/batchmulticlassnomaxsuppression/map/while/Exit_6',该节点具有动态op'Exit'。请改用model.executeAsync()。或者,为了避免动态操作,请指定输入[Postprocessor/BatchMultiClassNonMaxSuppression/map/TensorArrayStack\u 4/TensorArrayGatherV3]
。我的错是,我以为
executeAsync
是您自己定义的函数。我编辑了我的问题我按照您的建议更新了代码(也在问题中),但仍然出现以下错误:
Uncaught(in promise)TypeError:output.dataSync不是predict的函数(index.js:23)
感谢您的回答,但使用上述建议,它会打印错误消息:
output.print不是predict的函数
index.js:21未捕获(承诺)类型错误:output.data不是predict的函数(index.js:21)
您能用
executeAsync
的定义更新您的问题吗?对不起,我没有收到您的问题。我试图使用
model.execute
但我得到了以下错误:
错误:此执行包含节点'Postprocessor/batchmulticlassnomaxsuppression/map/while/Exit_6',该节点具有动态op'Exit'。请改用model.executeAsync()。或者,为了避免动态操作,请指定输入[Postprocessor/BatchMultiClassNonMaxSuppression/map/TensorArrayStack\u 4/TensorArrayGatherV3]
。我的错是,我以为
executeAsync
是您自己定义的函数。我编辑了我的问题我按照您的建议更新了代码(也在问题中),但仍然出现以下错误:
Uncaught(in promise)TypeError:output.dataSync不是predict(index.js:23)的函数
(4) [t, t, t, t]
0: t {kept: false, isDisposedInternal: false, shape: Array(3), dtype: "float32", size: 400, …}
1: t {kept: false, isDisposedInternal: false, shape: Array(2), dtype: "float32", size: 100, …}
2: t {kept: false, isDisposedInternal: false, shape: Array(2), dtype: "float32", size: 100, …}
3: t {kept: false, isDisposedInternal: false, shape: Array(1), dtype: "float32", size: 1, …}
length: 4
__proto__: Array(0)