最近在学习transformer,遇上了一些问题并成功解决,于是写个文章留个记录
一、环境配置
1. MMCV
问题:
配置环境时报错
AssertionError: MMCV==1.7.0 is used but incompatible. Please install mmcv>=1.2.4, <=1.4.0。
尝试一:降低了mmcv的版本,但与我的conda环境不兼容。
尝试二:进入mmdet/init.py将maxversion=1.4.0更改为1.7.0,成功通过编译,但不确定如此更改是否会存在BUG
2.APEX
问题:
安装apex时报错:if cached_x.grad_fn.next_functions[1][0].variable is not x:
IndexError: tuple index out of range
尝试:修改源代码中的apex/amp/utils.py文件,将
if cached_x.grad_fn.next_functions[1][0].variable is not x:
更改为
if cached_x.grad_fn.next_functions[0][0].variable is not x:
参考链接:深度学习Apex库出现报错‘IndexError: tuple index out of range‘的解决方法
二、运行报错
1.RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
尝试:根据提示定位到bbox_nms.py文件,debug后发现labels在cpu上,其他两个在GPU上,将labels放到GPU上就跑通
参考链接:解决RuntimeError: Expected all tensors to be on the same device, but found at least two devices
但也有找到关于降低版本的解决方案:RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
有尝试重新建个环境,但由于pytorch安装的实在太慢且又要重新pip install -r 故放弃
2.data[‘category_id‘]=self.cat_ids[label] IndexError:list index out of range
尝试:根据参考链接内的方法,将score_thr从0.05改为0.3后成功跑通
参考链接:DEBUG | mmdetection测试报错data[‘category_id‘]=self.cat_ids[label] IndexError:list index out of range
附:配置环境时的参考文章
深度学习之目标检测(Swin Transformer for Object Detection)
Swin-Transformer目标检测
Swin Transformer Object Detection 目标检测、问题汇总