Detectron2最近更新到了0.1.2版本,安裝的要求也改變了一些,最近在服務器上進行安裝(普通用戶權限),特記錄一下。
服務器配置
- 系統:Centox 7.0
- GPU:Tesla M60
- CUDA:10.1
- gcc: 7.3.1
基本配置及版本要求
- OS: Linux 或 macOX
- Python>=3.6
- PyTorch>=1.4
- opencv(python 版)(可選),用於demo運行和可視化
- 安裝pycocotools
安裝步驟
1. anaconda創建環境
conda create -n detectron2_1 python=3.6
2. 安裝pytorch 1.5
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
注意:
- “-c pytorch"的尾綴不能去掉。
如果已經在服務器上切換成清華的鏡像源,一定要加上”-c pytorch"的尾綴,因爲,此時,清華的鏡像源下安裝最新的PyTorch版本是1.4(於2020年5月9日記錄),只有從conda默認的pytorch下載環境下才能安裝1.5* - 安裝時必須保證安裝環境下的CUDA版本一定要選對,且必須基於指定的PyTorch版本,當初,筆者就去掉了-c pytorch,安裝成了1.4的版本,結果,在運行detectron2的安裝語句時,報出“ No CUDA runtime is found”的錯誤:
ERROR: Command errored out with exit status 1:
command: /home/lan/miniconda3/envs/detectron2_1/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-uq20_2or/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-uq20_2or/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-uq20_2or/pip-egg-info
cwd: /tmp/pip-req-build-uq20_2or/
Complete output (6 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-req-build-uq20_2or/setup.py", line 14, in <module>
assert torch_ver >= [1, 4], "Requires PyTorch >= 1.4"
AssertionError: Requires PyTorch >= 1.4
No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda-10.1'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py
後來,重新安裝PyTorch1.5時,加上"-c pytorch"的尾綴,則解決了該錯誤。
其他版本:按照PyTorch官網上的要求,依次進行選擇,找到對應的commend
查看pytorch是否能調用GPU(jupyter環境下)
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
輸出True則表示GPU版的Pytorch安裝成功。
3. 安裝其他依賴項
pip install cython pyyaml==5.1
pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
pip install opencv-python
pip install cython; pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
4. 安裝 detectron2
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
不報錯,正常安裝完成之後,各種顯示successfully即可。