detectron2安装(亲测好用)
先码一下服务器配置:
- NVIDIA GeForce RTX 3090
- CUDA Version: 12.0
官网配置要求:
- Linux or macOS with Python ≥ 3.7
- PyTorch ≥ 1.8 and torchvision that matches the PyTorch installation. Install them together at pytorch.org to make sure of this
- OpenCV is optional but needed by demo and visualization
bpbreid 要引入 functools 包,需要 python>3.8
所以:
创建环境:
conda create --name detectron python=3.8
conda activate detectron
安装pytorch:
cuda安11.3有报错:
RuntimeError:
The detected CUDA version (10.1) mismatches the version that was used to compile
PyTorch (11.3). Please make sure to use the same CUDA versions.
所以 cudatoolkit=10.1
# conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
接着验证cuda的可用性。
安装opencv:
pip install opencv-python
安装cpython:
pip install cython
安装pycocotools:
pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
# 下面的也可以
pip install pycocotools
安装detectron2:
- git clone
git clone https://github.com/facebookresearch/detectron2.git
- 由于师姐的服务器的卡是3090,直接安装 detectron2 会报错,需要对 detectron2 的 setup.py 进行修改。
- detectron2 的位置:
/home/huilin/detectron2
- In the last line of setup.py, you change from
cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
tocmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension.with_options(use_ninja=False)},
- detectron2 的位置:
- 安装
python -m pip install -e detectron2
我按上面的步骤来,装了2次都成功了,应该还是比较可行的