mmdetection訓練測試voc格數數據 1 mmdetection 安裝及測試 2voc數據集處理 3編譯 4訓練 測試

1 mmdetection 安裝及測試

1.1可以通過docker直接安裝

在docker hub上搜索mmdetection,選擇下載量最高的docker
docker pull vistart/mmdetection
經驗證該docker內,mmdetection版本爲2.2.0,mmcv版本爲0.62
編譯
安裝後直接跑程序會報編譯錯誤,查找後,應對mmdetection進行重現編譯,否則無法使用GPU。
先進入mmdetection文件夾
cd mmdetection
刪除該路徑下的build文件夾
rm -rf ./build
重新編譯mmdetection
pip install -v -e .
如果docker 內pip命令有問題,使用pip3命令或其他方式解決。
等待編譯完成。

1.2dockerfile安裝

下載mmdetection項目後
docker build -t mmdetection docker/
開啓docker時建議加上--shm-size,否則訓練時會報錯說內存過小。
sudo docker run -it --gpus all -p 7775:8888 --shm-size 8G -v /home/zhaobing:/workspace mmdetection:latest
測試安裝是否成功可以使用如下語句簡單測試

from mmdet.apis import init_detector, inference_detector

config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: https://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'
# init a detector
model = init_detector(config_file, checkpoint_file, device=device)
# inference the demo image
inference_detector(model, 'demo/demo.jpg')

2voc數據集處理

mmdetection默認使用coco格式,使用voc格式數據集可以轉換爲coco格式,或者按照本文的方式

2.2數據集位置

將數據集放到如下位置

2.3修改算法對應的config

如,configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py



將數據集由coco換爲voc0712.py

退到上級目錄找到base,找到faster_rcnn_r50_fpn.py,修改原VOC類的數目爲自己數據集的類別,不用+1


修改'../base/datasets/voc0712.py',註釋掉voc2012的內容,根據自己的需要對應訓練驗證的train.txt.val.txt

2.4修改mmdetection/mmdet/datasets目錄下voc.py類別

將class內容換爲自己數據集的內容


2.5修改mmdetection/mmdet/core/evaluation目錄下class_names.py

將class內容換爲自己數據集的內容


3編譯

每次針對不同算法完成上述操作,運行python setup.py install,重新編譯

4訓練

建立work_dirs文件夾
將下載的權重文件放到checkpoints文件夾

python tools/train.py configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py

測試

 python ./tools/test.py  configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py work_dirs/faster_rcnn_r50_fpn_1x_coco/latest.pth  --eval mAP

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章