利用mmdetection训练自己数据集过程error解决汇总

安装mmdetection首先要注意有几个包的版本要对应,我这里以mmdet==2.11为例。
(1)cython的版本不用太高,否则mmpycocotools安装不成功;

pip install cython==0.29.21

(2)mmcv需要安装完整版本mmcv-full;

pip install mmcv-full==1.4.1 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html

(3)cd到项目文件夹路径下后

pip install -r requirements.txt
pip install -v -e .

首先给出配置:

调整前后配置变化
调整前调整后(程序可正常运行)
GPURTX 3090GPURTX 3090
torch      1.9.0+cu111torch  1.8.1+cu111
torchvision0.10.0+cu111torchvision0.9.1+cu111
mmcv-full1.4.0mmcv-full1.5.1
mmdetection2.11mmdetection2

Model : swin transformer 为主干的Mask R-CNN模型

数据集格式:COCO格式

Error 1:

File “pycocotools/_mask.pyx”, line 1, in init pycocotools._mask
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

解决方法:跟大多数网友提到的一样,主要是numpy版本过低问题。

pip install --upgrade numpy

Error 2:

TypeError: MaskRCNN: SwinTransformer: __init__() got an unexpected keyword argument 'embed_dim'

解决方法:运行以下代码,mmdetection版本会自动调整到合适版本:

pip install -r requirements.txt #安装好给出的依赖包,这步很重要
cd mmdetection #cd到mmdetection项目路径下
pip install -v -e .

Error 3:

AssertionError: MMCV==1.4.5 is used but incompatible. Please install mmcv>=1.2.4, <=1.4.0.

一开始我尝试卸载已安装的mmcv,运行下面代码降低版本

pip install mmcv-full==1.4.0 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.1/index.html

但还是出现以下报错:

Error 4:

RuntimeError: CUDA error: no kernel image is available for execution on the device

解决方法:这个error困扰了我很久,很多网友认为torch版本与cuda版本不匹配、cuda版本没有与GPU算力对应(RTX 3090只能在cuda11.1以上运行),导致这个问题的出现,我试过降低torch版本(降为torch 1.8.1+cu111),没能解决问题。经过检查torch、cuda及mmdetection三者之间的版本对应,也没有发现问题。陷入了emo...后面无意中发现,问题出在一开始的mmcv版本问题上。考虑到mmcv 1.4.0版本对RTX 3090(或cuda 11.1)来说可能还是太低了,试着调高版本但是会出现Error 3的情况,最后找到./mmdet/__init__.py这个源码,发现mmcv_maximum_version这个参数限制了mmcv最高版本的安装,将它修改后(由1.4.0改为了1.6.0),程序正常运行!

Error 5

AssertionError: Incompatible version of pycocotools is installed. Run pip uninstall pycocotools first. Then run pip install mmpycocotools to install open-mmlab forked pycocotools

解决方法:运行以下命令:

pip uninstall pycocotools
pip install mmpycocotools

Error 6

File “pycocotools/_mask.pyx”, line 292, in pycocotools._mask.frPyObjects IndexError: list index out of rangeissues/154

解决方法:思路主要是把与Mask有关的代码块注释掉

Comment out the configuration related to the mask

可以参考这个博主写得这篇,他有提到Swin-Transformer-Object-Detection V2.11.0 训练visdrone数据(二)文件结构.├── coco_exps├── configs #configs主要修改的部分在这里,训练config也是从这里继承的│ ├── albu_example│ ├── atss│ ├── _base_ #最根本的继承│ │ ├── datasets #存在着不同数据集的训练方法,包含train_pipeline(augmentation), test_pipeline(TTA), data(batch_size, data rohttps://blog.csdn.net/qq_41627642/article/details/124810544Error 7

OSError: [WinError 1314] 客户端没有所需的特权。: 'D:\\Swin-Transformer-Object-Detection\\work_dirs\\mask_rcnn_swin_tiny_patch4_window7_mstrain_480-
800_adamw_1x_coco\\epoch_1.pth' -> 'D:\\Swin-Transformer-Object-Detection\\work_dirs\\mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_c
oco\\best_bbox_mAP.pth'

解决方法:以管理员运行Anaconda Prompt 重新运行以下训练命令,亲测可以解决。不过好像还有更好的办法?

python tools/train.py configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.py

Error 8

TypeError: expected string or bytes-like object

我出现这个问题是因为不想加载预训练权重,pretrained=None,结果导致报错。重新加上就好了。

解决方法:

ERROR 9

AssertionError: The `num_classes` (5) in YOLOV3Head of MMDataParallel does not matches the length of `CLASSES` 80) in CocoDataset
原因:修改的本地环境与训练环境不一致

 

解决方法:
我有两个环境路径
1、C:\Users\hlj\.conda\envs\
2、D:\ProgramData\Anaconda3\envs

1是我的训练环境路径,2是我本地环境路径。
只要将想要的训练环境从路径1挪到路径2,
然后打开编译器重新执行安装命令:
pip install -r requirements.txt
pip install -v -e .  

ERROR 10

data[‘category_id‘]=self.cat_ids[label] IndexError:list index out of range

解决方法:

DEBUG | mmdetection测试报错data[‘category_id‘]=self.cat_ids[label] IndexError:list index out of range_data['category_id'] = self.cat_ids[label] indexerr_南瓜派三蔬的博客-CSDN博客https://blog.csdn.net/qq_36810398/article/details/116994577

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HUANGL1NJIE

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值