用途:在昇腾NPU容器中从源码安装NPU兼容版本的detectron2,适用于实例分割、目标检测等模型的开发。
主要能力:提供从源码安装detectron2的流程,并给出安装后的验证方法,包括确认导入成功以及检查环境中不存在CUDA相关路径,以避免误装预编译CUDA版本导致运行时错误。
使用方式:先确认前置条件,即mmcv已安装(可用python -c "import mmcv; print(mmcv.version)"检查),容器中已安装Ascend CANN和torch_npu,且工作目录已挂载。随后激活conda环境并从源码安装:source /opt/conda/bin/activate <conda-env-name>,pip install git+https://github.com/facebookresearch/detectron2.git。安装后执行python -c "import detectron2; print('detectron2 installed')"验证导入,并用python -c "import site; print([p for p in site.getsitepackages() if 'cuda' in p.lower()])"检查,输出应为空列表;若包含cuda相关路径,需卸载后重新从源码安装:pip uninstall detectron2 -y,再执行pip install git+https://github.com/facebookresearch/detectron2.git。
适用场景:昇腾NPU环境下进行detectron2相关模型开发与调试。
限制与常见问题:NPU环境必须从源码安装,预编译CUDA版本会导致运行时错误;可能出现依赖冲突,必要时先卸载已安装的CUDA版本detectron2。安装前可向用户确认是否已安装detectron2及其版本,以及当前环境是NPU还是CUDA;安装后必须验证site.getsitepackages()中没有cuda相关路径,否则需卸载重装。