1 已经成功安装完mmcv 2.1.0 ,引入模块时报错 name ‘ModulatedDeformConv2d’ is not defined
- 第一步先,pip show mmdet,查看是否安装了mmdet, 安装后,再次运行;
- 又报了上述ImportError: DLL load failed while importing _ext: 找不到指定的程序。
安装的mmcv、mmdet和已有的torch cuda等版本不对应。
检查安装的pytorch对应的版本,如
import torch
print(torch.__version__) #注意是双下划线
我的是cuda11.8+torch2.2.1,但是安装的mmcv是1.6.2版本不对应。
在mmcv官网查看对应版本,https://mmcv.readthedocs.io/zh-cn/stable/get_started/installation.html
点击左下角,切换mmcv版本,对应版本下根据系统类型选择安装命令。比如对于稳定的mmcv2.0.0版本,最高只对应到cuda11.8和torch2.0.x,但是我之前装的是torch2.2.1就不匹配,索性我又重新建了个mmcv虚拟环境
- 在mmcv虚拟环境下,又重新装了cuda11.8+torch2.0.0
https://pytorch.org/get-started/previous-versions/
然后又复制上述提到的mmcv2.0.0版本的安装指令,安装mmcv。 - 选择与mmcv对应的mmdet, https://mmdetection.readthedocs.io/en/v3.0.0/get_started.html
直接使用pip装,pip install mmdet==3.0.0
安装完成后,from mmcv.ops import ModulatedDeformConv2d 不再报错。