mmdetection訓(xùn)練測(cè)試voc格數(shù)數(shù)據(jù)

1 mmdetection 安裝及測(cè)試

1.1可以通過docker直接安裝

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

1.2dockerfile安裝

下載mmdetection項(xiàng)目后
docker build -t mmdetection docker/
開啟docker時(shí)建議加上--shm-size,否則訓(xùn)練時(shí)會(huì)報(bào)錯(cuò)說(shuō)內(nèi)存過小。
sudo docker run -it --gpus all -p 7775:8888 --shm-size 8G -v /home/zhaobing:/workspace mmdetection:latest
測(cè)試安裝是否成功可以使用如下語(yǔ)句簡(jiǎn)單測(cè)試

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數(shù)據(jù)集處理

mmdetection默認(rèn)使用coco格式,使用voc格式數(shù)據(jù)集可以轉(zhuǎn)換為coco格式,或者按照本文的方式

2.2數(shù)據(jù)集位置

將數(shù)據(jù)集放到如下位置/mmdetection/data/VOCdevkit/VOC2007 文件夾下為VOC格式的三個(gè)文件夾,Annotations JPEGImages ImageSets

image.png

2.3修改算法對(duì)應(yīng)的config

如,configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py


image.png

將數(shù)據(jù)集由coco換為voc0712.py

退到上級(jí)目錄找到base,找到faster_rcnn_r50_fpn.py,修改原VOC類的數(shù)目為自己數(shù)據(jù)集的類別,不用+1

image.png

修改'../base/datasets/voc0712.py',注釋掉voc2012的內(nèi)容,根據(jù)自己的需要對(duì)應(yīng)訓(xùn)練驗(yàn)證的train.txt.val.txt
image.png

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

將class內(nèi)容換為自己數(shù)據(jù)集的內(nèi)容


image.png

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

將class內(nèi)容換為自己數(shù)據(jù)集的內(nèi)容


image.png

3編譯

每次針對(duì)不同算法完成上述操作,運(yùn)行python setup.py install,重新編譯

4訓(xùn)練

建立work_dirs文件夾
將下載的權(quán)重文件放到checkpoints文件夾

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

測(cè)試

 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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容