Linux系统下detectron2安装(cuda11为例)
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.72.配置CUDA和cudnn
3.配置pytorch :
首先激活剛才創建的環境
然后安裝pytorch
參考官網:https://pytorch.org/get-started/locally/
這里以pytorch1.8.0+cuda11.1為例(具體安裝哪個版本可根據自己cuda版本選,30系列的顯卡只支持cuda版本為11及以上,這里注意一下!!!)
檢查一下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庫
安裝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版本可通過以下命令查看!)
這里以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
總結
以上是生活随笔為你收集整理的Linux系统下detectron2安装(cuda11为例)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 域名解析的过程
- 下一篇: LinuxC语言简单实现图片加马赛克-标