mmdetection训练出现:IndexError: list index out of range 错误

mmdetection训练出现:IndexError: list index out of range 错误

文章目录:


我的环境:

  • Ubuntu18.04
  • TorchVision: 0.6.0
  • OpenCV: 4.2.0
  • MMCV: 0.5.5
  • MMDetection: 2.0.0+d9c8f14
  • MMDetection Compiler: GCC 7.5
  • MMDetection CUDA Compiler: 10.2

训练的模型是:Retinanet


1 问题分析

在使用mmdetection2.0框架训练目标检测模型时候,出现IndexError: list index out of range错误,具体内容如下图,首先从这个错误的类型我们可以看出是索引超过了列表的长度,导致IndexError错误
在这里插入图片描述

1.1 尝试解决错误:第一次

根据这个错误,很容易想到是否是类别写的不正确,于是去检查如下三个文件:

  • mmdetection/mmdet/datasets/voc.py:中的CLASSED变量对应的类别是否正确
  • mmdetection/mmdet/core/evaluation/class_names.py:voc_classes()函数返回的类别是否正确
  • mmdetection/configs/_base_/models/retinanet_r50_fpn.py:中num_classes对应的类别数是否正确

结果反复检查了好几遍,还是没有解决这个问题,当然如果你遇到这个问题,很可能就是因为类别写的不对,你一定要仔细、仔细、仔细检查

1.2 尝试解决错误:第二次

自己解决不了,于是就去逛github mmdetection的官网,然后乖乖查看issues,issues中好多说是类别的问题,还有一个人说是学习率太大导致的,我一脸迷惑,信以为真,就尝试了一下(参考


ONE YEARS LATER


一顿尝试,最终还是不行,错误重现!!!

2 我的问题解决方式

我最开始编译的mmdetection环境路径为:

/home/shl/shl/mmdetection

但是我后面训练自己的另外一个数据集的时候,是直接把这个编译好的mmdetection拷贝一份出来,会出一定的问题,比如:

cp -r mmdetection mmdetection_clothes

然后在/home/shl/shl/mmdetection_clothes中修改类别,但是最终还是会去:/home/shl/shl/mmdetection/mmdet下面读取类别信息,用pip list 可以查看到mmdetection的路径

(mmdetection) shl@zfcv:~/shl/mmdetection$ pip list
Package                Version             Location
---------------------- ------------------- -------------------------
absl-py                0.9.0
addict                 2.2.1
cachetools             4.1.0
certifi                2020.4.5.1
chardet                3.0.4
click                  7.1.2
cycler                 0.10.0
Cython                 0.29.19
Flask                  1.1.2
future                 0.18.2
google-auth            1.17.2
google-auth-oauthlib   0.4.1
grpcio                 1.29.0
idna                   2.9
importlib-metadata     1.6.1
itsdangerous           1.1.0
Jinja2                 2.11.2
kiwisolver             1.2.0
Markdown               3.2.2
MarkupSafe             1.1.1
matplotlib             3.2.1
mmcv                   0.5.5
mmdet                  2.0.0+d9c8f14       /home/shl/shl/mmdetection    # 这里可以看到,mmdetection_clothes训练时还是在这里调用mmdet下的类别相关信息
numpy                  1.18.4
oauthlib               3.1.0
opencv-python          4.2.0.34
pandas                 1.0.4
Pillow                 7.1.2
pip                    20.0.2
protobuf               3.12.2
pyasn1                 0.4.8
pyasn1-modules         0.2.8
pycocotools            2.0
pyparsing              2.4.7
python-dateutil        2.8.1
pytz                   2020.1
PyYAML                 5.3.1
requests               2.23.0
requests-oauthlib      1.3.0
rsa                    4.6
scipy                  1.4.1
seaborn                0.10.1
setuptools             46.4.0.post20200518
six                    1.15.0
tensorboard            2.2.2
tensorboard-plugin-wit 1.6.0.post3
terminaltables         3.1.0
torch                  1.5.0
torchvision            0.6.0
tqdm                   4.46.1
urllib3                1.25.9
Werkzeug               1.0.1
wheel                  0.34.2
yapf                   0.30.0
zipp                   3.1.0
(mmdetection) shl@zfcv:~/shl/mmdetection$

所以最后的解决方式,在/home/shl/shl/mmdtection这个原始的路径下修改类别,然后训练,不要拷贝出来一份!我就是想训练多个数据集才这样干的,至于后面有没有什么解决方式,我再尝试!

猜你喜欢

转载自blog.csdn.net/weixin_41010198/article/details/107067843