IndexError: list index out of range

IndexError: list index out of range

Traceback (most recent call last):
File “C:/Users/liqiang/Desktop/PyTorch_YOLOv3/detect.py”, line 145, in
print(“\t+ Label: %s, Conf: %.5f” % (classes[int(cls_pred)], cls_conf.item()))
IndexError: list index out of range

此错误的原因

(1)list[index]中的index超出了范围

(2)list没有相应的元素

而且定为到报错的行数时,同长会有for循环,修改的办法有:

输入以下代码:

print("\t+ Label: %s, Conf: %.5f" % (classes[int(cls_pred)], cls_conf.item()))

修改为:(类似于自己的代码修改)—–试试看,也许可行

try:
    print("\t+ Label: %s, Conf: %.5f" % (classes[int(cls_pred)], cls_conf.item()))
except:
    continue

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2022年4月4日 下午6:00
下一篇 2022年4月4日 下午6:05

相关推荐