Python_demo ONNXruntime 错误
TJJ120635 opened this issue · 0 comments
TJJ120635 commented
在使用 onnxruntime 示例进行推理时出现了以下错误:
root@ft:~/demo_onnxruntime_lite# python v5lite.py --modelpath v5Lite-e-sim-320.onnx
(6300, 85)
[[1026, 556, 282, 704], [1031, 565, 262, 703], [1031, 552, 270, 722], [1033, 580, 257, 675], [1033, 569, 264, 684], [1022, 563, 299, 667], [1021, 565, 287, 675], [1025, 563, 295, 670], [1019, 564, 289, 677], [1026, 566, 295, 660], [1018, 569, 291, 667], [1031, 556, 268, 684], [995, 528, 311, 741]]
Traceback (most recent call last):
File "v5lite.py", line 152, in <module>
srcimg = net.detect(img)
File "v5lite.py", line 132, in detect
srcimg = self.postprocess(srcimg, outs, (newh, neww, top, left))
File "v5lite.py", line 85, in postprocess
box_index.append(i[0])
IndexError: invalid index to scalar variable.
可能原因是 NMS 方法的返回数组格式问题(版本opencv 4.7.0_py37_armv7l)
没有正确读取到 postprocess 中的 indices = cv2.dnn.NMSBoxes(boxes, confidences, self.confThreshold, self.nmsThreshold) 导致
原代码为:
./python_demo/onnxruntime/v5lite.py 82行
for i in indices:
box_index.append(i[0])
经过修改如下,可以修复问题:
if indices.ndim == 1:
for i in indices:
box_index.append(i)
elif indices.ndim == 2:
for i in indices:
box_index.append(i[0])
else:
raise ValueError("Unexpected shape of indices")