当前位置: 代码迷 >> 综合 >> yolo运行报错:IndexError: invalid index to scalar variable.
  详细解决方案

yolo运行报错:IndexError: invalid index to scalar variable.

热度:14   发布时间:2023-12-15 15:52:38.0

代码:

yolo_layers = [layers[i[0] - 1] for i in network.getUnconnectedOutLayers()]

报错:

Traceback (most recent call last):File "Run.py", line 201, in <module>main()File "Run.py", line 137, in maindetections = yolo.detect(yolo_img)File "code/3D-BoundingBox-master/yolo/yolo.py", line 34, in detectln = [ln[i[0] - 1] for i in self.net.getUnconnectedOutLayers()]File "code/3D-BoundingBox-master/yolo/yolo.py", line 34, in <listcomp>ln = [ln[i[0] - 1] for i in self.net.getUnconnectedOutLayers()]
IndexError: invalid index to scalar variable.

原因:
opencv版本不同引起的输出格式不同

解决:

yolo_layers = [layers[i - 1] for i in network.getUnconnectedOutLayers()]

参考:
https://stackoverflow.com/questions/69834335/loading-yolo-invalid-index-to-scalar-variable

  相关解决方案