YunYang1994/tensorflow-yolov3 IndexError: list index out of range 解决办法
YunYang1994/tensorflow-yolov3 IndexError: list index out of range 解決辦法
- 原項目地址:YunYang1994/tensorflow-yolov3
- 報錯描述:
- 詳細描述:
- 尋找錯誤原因:
- 總結:
原項目地址:YunYang1994/tensorflow-yolov3
報錯描述:
運行識別程序 video_demo.py 時,程序報錯:
D:\Yolov3_Tensorflow\python\python.exe D:/Yolov3_Tensorflow/tensorflow-yolov3/video_demo.py 2019-10-10 08:26:58.675604: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2019-10-10 08:26:59.363176: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1411] Found device 0 with properties: name: GeForce MX250 major: 6 minor: 1 memoryClockRate(GHz): 1.582 pciBusID: 0000:01:00.0 totalMemory: 2.00GiB freeMemory: 1.62GiB 2019-10-10 08:26:59.363377: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1490] Adding visible gpu devices: 0 2019-10-10 08:27:00.278345: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-10-10 08:27:00.278458: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] 0 2019-10-10 08:27:00.278519: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0: N 2019-10-10 08:27:00.278730: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1103] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1374 MB memory) -> physical GPU (device: 0, name: GeForce MX250, pci bus id: 0000:01:00.0, compute capability: 6.1) 2019-10-10 08:27:18.867149: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.13GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available. 2019-10-10 08:27:18.894705: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.14GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available. 2019-10-10 08:27:18.898060: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.13GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available. 2019-10-10 08:27:19.032698: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.60GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available. 2019-10-10 08:27:19.109551: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 1.56GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available. 2019-10-10 08:27:19.123356: W tensorflow/core/common_runtime/bfc_allocator.cc:215] Allocator (GPU_0_bfc) ran out of memory trying to allocate 2.06GiB. The caller indicates that this is not a failure, but may mean that there could be performance gains if more memory were available. Traceback (most recent call last):File "D:/Yolov3_Tensorflow/tensorflow-yolov3/video_demo.py", line 141, in <module>image = utils.draw_bbox(frame, bboxes)File "D:\Yolov3_Tensorflow\tensorflow-yolov3\core\utils.py", line 83, in draw_bboxbbox_color = colors[class_ind] IndexError: list index out of rangeProcess finished with exit code 1詳細描述:
程序運行成功會打開識別或者視頻流進行識別并畫出識別框,在畫面靜止的狀態下,運行貌似穩定并能準確顯示識別框,當畫面有較大幅度動作時,會立即出現上述報錯。
尋找錯誤原因:
1、在檢查的過程中偶然看見程序說 ./data/classes/voc.names 文件不存在,當時沒在意。因為查看文件夾,voc.names 文件確實存在。
2、后來查看 video_demo.py 文件,看到兩個參數,突然想起什么,input_size = 416 可能是識別時識別框預設大小,而num_classes = 80 依稀記得是識別分類的數量。
于是打開 voc.names 查看,發現里面只有20個類,而打開 coco.names ,發現有80個類,這應該多少有點問題:
3、于是打開 config.py 文件,將 __C.YOLO.CLASSES 參數由 "./data/classes/voc.names" 改成了 "./data/classes/coco.names"。
4、運行程序,沒有再出現程序報錯,識別也良好!
總結:
識別使用的權重文件一定要與我們識別類的 .names 文件相對應(猜測權重文件中記錄的只是類序號,它轉換成文字表示需要 .names 文件支持),同時我們在 video_demo.py 中填寫的 num_classes 參數也要與 .names 文件中的類數量一致。
(我本次使用的權重文件為 yolov3_coco_demo.ckpt )
總結
以上是生活随笔為你收集整理的YunYang1994/tensorflow-yolov3 IndexError: list index out of range 解决办法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Opencv 深度学习中为什么普遍使用B
- 下一篇: YunYang1994/tensorfl