安装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 .
首先给出配置:
调整前 | 调整后(程序可正常运行) | ||
GPU | RTX 3090 | GPU | RTX 3090 |
torch | 1.9.0+cu111 | torch | 1.8.1+cu111 |
torchvision | 0.10.0+cu111 | torchvision | 0.9.1+cu111 |
mmcv-full | 1.4.0 | mmcv-full | 1.5.1 |
mmdetection | 2.11 | mmdetection | 2 |
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
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
解决方法: