天天看點

配置低版本CUDA和pytorch、mmdetection

pytorch 0.4.1 docker位址:

https://hub.docker.com/r/linkoffate/torchen

https://hub.docker.com/r/airaria/pytorch0.4.1

直接上幹貨,CUDA9.0版本對應的pytorch是0.4.1,使用其他版本pytorch不支援,一定要安裝0.4.1版本,github上的mmdetection安裝對應CUDA9.0的在branch0.4.1裡,但是注意!!!!!!!!!!github上不知道為什麼,pytorch0.4.1分支裡的少一些檔案我安裝了好幾次進到提示少deform_conv_cuda等檔案,又對比主分支才發現少了很多檔案.

解決辦法:

1.git項目(不在github上)

git clone https://gitee.com/mirrors/mmdetection.git

2.切換到pytorch-0.4.1分支(針對CUDA9.0使用者)

cd mmdetection

git checkout pytorch-0.4.1

3.安裝

3.1建立虛拟環境(需要python3.5+)

conda create -n python3.5 python=3.5.4

conda activate python3.5

3.2安裝依賴庫(兩種安裝方式二選一)

 conda install pytorch=0.4.1 -c pytorch #pip install pytorch=0.4.1 -c pytorch

conda install cython #pip install cython

cd mmdetection#如果已經在此目錄不需要此條指令

./compile.sh

3.3安裝mmcv

git clone https://github.com/open-mmlab/mmcv.git

cd mmcv

pip install .

4.安裝mmdet

python setup.py install #pip install .

測試代碼

預訓練模型需要自己下載下傳

  1. import mmcv
  2. from mmcv.runner import load_checkpoint
  3. from mmdet.models import build_detector
  4. from mmdet.apis import inference_detector, show_result
  5. cfg = mmcv.Config.fromfile('/home/stardust/mmdetection/configs/faster_rcnn_r50_fpn_1x.py')
  6. cfg.model.pretrained = None
  7. # 建構網絡,載入模型
  8. model = build_detector(cfg.model, test_cfg=cfg.test_cfg)
  9. # _ = load_checkpoint(model, 'https://s3.ap-northeast-2.amazonaws.com/open-mmlab/mmdetection/models/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth')
  10. # 如果通過網盤下載下傳,取消下一行代碼的注釋,并且注釋掉上一行
  11. _ = load_checkpoint(model, 'model/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth')
  12. # 測試一張圖檔
  13. img = mmcv.imread('test.jpg')
  14. result = inference_detector(model, img, cfg)
  15. show_result(img, result)
  16. # 測試多張圖檔
  17. # imgs = ['test1.jpg', 'test2.jpg']
  18. # for i, result in enumerate(inference_detector(model, imgs, cfg, device='cuda:0')):
  19. # print(i, imgs[i])
  20. # show_result(imgs[i], result)
配置低版本CUDA和pytorch、mmdetection

 原文連結:http://kmanong.top/kmn/qxw/form/article?id=17694&cate=56

如果這篇文章幫助到了你,你可以請作者喝一杯咖啡

配置低版本CUDA和pytorch、mmdetection