Features
Install detectron2 from source in an Ascend NPU container (NPU-compatible version)
Prerequisites
- mmcv is installed
- Ascend CANN and torch_npu are installed in the container
- The working directory is mounted
Usage
Step 1: Confirm prerequisites
Ensure mmcv is installed:
python -c "import mmcv; print(mmcv.__version__)"
Step 2: Install detectron2 from source
Important: In an NPU environment, you must install from source; do not use the precompiled CUDA version!
source /opt/conda/bin/activate <conda-env-name>
pip install git+https://github.com/facebookresearch/detectron2.git
Step 3: Verify the installation
python -c "import detectron2; print('detectron2 installed')"
NPU verification(critical step):
python -c "import site; print([p for p in site.getsitepackages() if 'cuda' in p.lower()])"
# 应输出空列表,确保没有安装CUDA版本
If the output contains cuda-related paths, the CUDA version was installed; you need to uninstall it and reinstall from source:
pip uninstall detectron2 -y
pip install git+https://github.com/facebookresearch/detectron2.git
Common Issues
- CUDA version issue: In an NPU environment, you must install from source; using the precompiled CUDA version will cause runtime errors
- Dependency conflict: You may need to first uninstall the installed CUDA version of detectron2
Decision Guidance
Ask the user:
- Is detectron2 already installed? What version?
- Is the current environment NPU or CUDA?
Verification is required after installation:
- Confirm that site.getsitepackages() contains no cuda-related paths
- Otherwise, you need to uninstall and reinstall