py-faster-rcnn出现BB = BB[sorted_ind, :] IndexError: too many indices for array可能解决方法

      今天在py-faster-rcnn中进行test测试,也不知道咋搞得,以前跑得好好的现在出现如下错误:

BB = BB[sorted_ind, :] IndexError: too many indices for array error from voc_eval function

经过逐步排查后发现可能是sorted_ind为空导致的,但一时半克不知如何解决,于是去网上找呀找,具体的解决方法大致分两种:

一、在中文blog中好几篇感觉都是大同小已的,大致就是说模型没有学习到东西。原话大致如下:

“IndexError: too many indices for array这个错是说没有学习到东西,我用了[4000,2000,4000,2000]试了一下也不行。不过能看到这个错误,如果你的数据集做的没有问题的话,用[80000,40000,80000,40000](亲测大概16小时,1341张图)运行你自己的数据集就没问题了。为了省时间我用的是[40000,20000,40000,2000](大概8小时,50张图)。这个时间好像与图片大小和图片数量关系不大。感觉只与迭代次数有关。“参见:https://www.cnblogs.com/hansjorn/p/7724852.html

二、GitHub上的一篇blog说是问题出在pascal_voc.py/_write_voc_results_file这个函数,具体是pascal_voc.py文件中的第251行中的一条判断语句存在bug造成的,造成bug的原因是numpy.ndarray数据类型和list不同,由于简短我把blog直接粘贴过来如下:

I have seen a lot of posts regarding the error BB = BB[sorted_ind, :] IndexError: too many indices for array which i as well encountered while running the evaluation on a very weakly trained model. I actually found a bug in the file pascal_voc.py which causes this issue.
The all_boxes parameter for the py-faster-rcnn/lib/datasets/pascal_voc.py/evaluate_detection() function in pascal_voc.py is a list of numpy arrays. But in pascal_voc.py/_write_voc_results_file(all_boxes) function in line 251 we check if the

dets == []
but here dets is of type <class 'numpy.ndarray'> and the statement in line 251 evaluates to False leading to consider the empty array being written into the output detection file.

This file with some empty arrays when read in py-faster-rcnn/lib/datasets/eval_voc.py/voc_eval() in line 148throws and error as BB is just an array.

Solution : In pascal_voc.py/_write_voc_results_file(all_boxes) edit to line 251 should be

dets.tolist() == []

This wont throw the error any more !

Kudos !

”原文链接:https://github.com/rbgirshick/py-faster-rcnn/issues/855

由于我已经训练好了model,只是测试呀,前面test都没问题呀,也没有更改其他文件呀,按理不可能出现这问题的,也不知道今天computer发啥神经了,对于上述两种方法我采用第二种测试通过了,第一种就没试了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值