基于官網(wǎng)的getstart教程
https://github.com/open-mmlab/mmdetection/blob/master/docs/zh_cn/get_started.md
一:查看當前顯卡的cuda版本
在終端輸入:
nvidia-smi
即可查看cuda版本

image.png
二:到pytorch官網(wǎng)獲得下載命令
官網(wǎng)地址:https://pytorch.org/
選擇好對應版本后,復制下面的命令到終端粘貼執(zhí)行。

image.png
但是我裝好之后,看pip list,發(fā)現(xiàn)torch和torchvision的版本,后面跟的cu并不是116,而是113,我不清楚為什么,但是貌似沒有影響使用。

image.png
三、安裝mmdet
官方推薦先安裝opmim,然后使用mim安裝mmdet。就是下面兩行命令,這樣可以自動安裝相關(guān)的依賴。
pip install openmim
mim install mmdet
四、驗證
官方給出的驗證代碼如下,如果配置成功,按理說是可以跑通的。

image.png
這里要注意一下,以上的環(huán)境配置過程中沒有下載mmdetection的項目,也沒有checkpoint文件夾,也沒有與訓練模型權(quán)重參數(shù)的文件pth文件。直接跑這個要報錯的
要執(zhí)行以下步驟(在jupyternotebook里執(zhí)行的)
1、克隆項目
!git clone https://github.com/open-mmlab/mmdetection.git
2、進入項目文件夾
%cd mmdetection
3、新建checkpoints文件夾
!mkdir checkpoints
4、進入checkpoints文件夾
%cd checkpoints
5、下載權(quán)重文件
!wget https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
這一步可能有問題,我怎么知道去哪里下載權(quán)重文件?
https://github.com/open-mmlab/mmdetection/tree/master/configs/faster_rcnn
在github官方倉庫里面去找,config文件夾里面,找到對應的模型文件夾,然后下面有這個模型不同的權(quán)重文件,就是右邊的model,左鍵直接下載,或者右鍵復制鏈接地址,使用上面的wget命令下載。

image.png
6、返回上級目錄
cd兩點是返回上級目錄,這里就是回到mmdetection目錄。
%cd ..

image.png
7、驗證是否成功(官方給出的驗證方法)
from mmdet.apis import init_detector, inference_detector
config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# 從 model zoo 下載 checkpoint 并放在 `checkpoints/` 文件下
# 網(wǎng)址為: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
# 初始化檢測器
model = init_detector(config_file, checkpoint_file, device=device)
# 推理演示圖像
inference_detector(model, 'demo/demo.jpg')