Linux系统下detectron2安装(cuda11为例)
**Linux系统下detectron2安装**detectron2官方Requirements:Linux or macOS with Python ≥ 3.6(python版本需大于3.6)PyTorch ≥ 1.8 and torchvision that matches the PyTorch installation. Install them together at pytorch.o
Linux系统下detectron2安装(cuda11为例)
detectron2官方Requirements
1.Linux or macOS with Python ≥ 3.6(python版本需大于3.6)
2.PyTorch ≥ 1.8 and torchvision that matches the PyTorch installation. Install them together at pytorch.org to make sure of this(1.8版本以上去确保torchvision和pytorch相匹配)
3.OpenCV is optional but needed by demo and visualization(OpenCV可根据自己需要装)
1.新建一个conda环境 :这里我们新建一个名字为detectron, python版本为3.7的conda环境(这里推荐安装Anaconda管理自己的环境包)
conda create -n detectron python=3.7
2.配置CUDA和cudnn
3.配置pytorch :
首先激活刚才创建的环境
conda activate detectron
然后安装pytorch
参考官网:https://pytorch.org/get-started/locally/
这里以pytorch1.8.0+cuda11.1为例(具体安装哪个版本可根据自己cuda版本选,30系列的显卡只支持cuda版本为11及以上,这里注意一下!!!)
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
检查一下pytorch是否安装成功:
python
import torch # 如正常则静默
a = torch.Tensor([1.]) # 如正常则静默
a.cuda() # 如正常则返回"tensor([ 1.], device='cuda:0')"
from torch.backends import cudnn # 如正常则静默
cudnn.is_acceptable(a.cuda()) # 如正常则返回 "True"
exit()
4.detectron2安装
(1)安装detectron依赖
安装opencv库
pip install opencv-python
安装fvcore
pip install fvcore
安装cython
pip install cython
安装pycocotools:
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
第一种方式有点慢,选择下一种方式安装
pip install pycocotools
现在进入正题安装detectron2!!!
detectron2安装有两种方式:
(1)从源代码构建:需要 gcc & g++ ≥ 5.4
#直接从源代码安装
python -m pip install ‘git+https://github.com/facebookresearch/detectron2.git’
#或者拉到本地直接安装:
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2
第一种方式有时候安装会报错!!!!这里推荐第二种安装方式
(2) 从官方预构建的环境安装
这里我们参考detectron2中给出的安装命令,进入detectron2官网安装,会看到以下很多版本(现在已经更新到0.6,也可以装之前的版本)
根据自己机器的cuda版本以及torch版本点开选择相应的安装命令
(如果不知道自己的torch以及python版本可通过以下命令查看!)
python
import torch
print(torch.__version__)
exit()
这里以cuda11.1+torch1.8为例安装detectron2:
python -m pip install detectron2==0.6 -f \
https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.8/index.html
至此安装结束!
[1]: https://blog.csdn.net/weixin_44151034/article/details/118368323
[2]:https://github.com/facebookresearch/detectron2/releases
[3]: https://detectron2.readthedocs.io/en/latest/tutorials/install.html
更多推荐
所有评论(0)