MMDetection是一個基於Pytorch實現的深度學習和目標檢測代碼庫,包含了Faster-RCNN,YOLO,SSD等主流的目標檢測算法代碼和已經訓練好的模型,方便我們進行目標檢測算法的研究.MMDetection的安裝步驟如下:
1. 創建一個Conda環境並Activate,很簡單,就不詳細說了;
2. 安裝Pytorch:
conda install pytorch=1.6.0 torchvision torchaudio cudatoolkit=10.1 -c pytorch
一定要注意根據CUDA版本選擇適當的Pytorch版本,比如CUDA版本是10.1,可以選擇Pytorch版本為1.6.0,如果CUDA版本是10.0及以下的,需要升級到至少10.1,否則MMDetection運行時會報錯;
3. 使用Git下載mmcv和mmdetection,可以從Github上下載,但是速度比較慢,建議從Gitee下載:
git clone https://gitee.com/cubone/mmdetection.git
git clone https://gitee.com/cubone/mmcv.git
4. 安裝mmcv或者mmcv-full,其中mmcv是CPU版本,mmcv-full是GPU版本,根據Pytorch和CUDA版本選擇合適的mmcv-full版本:
pip install mmcv-full==1.1.5+torch1.6.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html
5. 檢測是否安裝成功,運行下面的Demo代碼:
from mmdet.apis import init_detector, inference_detector config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py' device = 'cuda:0' # init a detector model = init_detector(config_file, device=device) # inference the demo image inference_detector(model, 'demo/demo.jpg')
如果沒有報錯,則說明安裝成功!