初次跑通MMDetection的MaskRCNN
Demo
惯例先跑一下demo,新建一个HellowMMDection.py,将这个脚本放在./demo中去:
# Check Pytorch installation
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
# Check MMDetection installation
import mmdet
print(mmdet.__version__)
# Check mmcv installation
from mmcv.ops import get_compiling_cuda_version, get_compiler_version
print(get_compiling_cuda_version())
print(get_compiler_version())
from mmdet.apis import inference_detector, init_detector, show_result_pyplot
# Choose to use a config and initialize the detector
config = 'configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py'
# Setup a checkpoint file to load
checkpoint = 'checkpoints/mask_rcnn_r50_fpn_1x_coco_20200205-d4b0c5d6.pth'
# initialize the detector
model = init_detector(config, checkpoint, device='cuda:0')
# Use the detector to do inference
img = 'demo/demo.jpg'
result = inference_detector(model, img)
# Let's plot the result
show_result_pyplot(model, img, result, score_thr=0.3)
然后在终端输入,就能跑通demo了,输出下面的图片:
./mmdetection$ python ./demo/hellowworld.py

Train
修改coco_instance.py下面的coco数据集的路径data_root,换成自己的coco数据集的路径:

将注释压缩包,train图片和val图片的压缩包解压放在coco/里面,就像下面的文件路径一样:

然后就能开始train了
python ./tools/train.py configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py
Test
训练完毕之后将训练出来的模型放在项目根目录下的checkpoints文件夹下,输入下面的命令就能开始test了,注意后面加上需要测试输出的指标bbox和segm
python ./tools/test.py configs/mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py checkpoints/mask_rcnn_r50_fpn_1x_coco_20200205-d4b0c5d6.pth --eval bbox segm

本文介绍初次跑通MMDetection的MaskRCNN的过程。包括跑demo,新建脚本并在终端输入命令;训练时修改coco数据集路径,解压相关压缩包;测试时将训练模型放指定文件夹,输入命令并加上测试指标bbox和segm。

6804

被折叠的 条评论
为什么被折叠?



