跑通MMDetection的MaskRCNN

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

初次跑通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

 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值