使用mmdetection检测并存储结果
使用voc格式样本训练
修改mmdet/datasets/voc.py文件中类别,注意格式别出错
CLASSES = ('bird-nest',)
然后修改配置文件,其中img_scale是你输入图片的宽高,num_classes=数据集类别数+1(背景),其他超参按照官网教程修改即可。
如果要做精度评价的话,要记得修改mmdet/core/evaluation/class_names.py中的类别跟数据集的类别一致。
检测并保存结果(添加nms)
由于我在超算上运行,所以没有做结果显示,只是保存为了jpg
在根目录下新建一个demo.py文件,并运行。
import mmcv
import os
import numpy as np
from mmcv.runner import load_checkpoint
from mmdet.models import build_detector
from mmdet.apis import init_detector, inference_detector, show_result
model = init_detector('configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py', 'work_dirs/faster_rcnn_r50_fpn_1x_voc0712/epoch_8.pth', device='cuda:0')
input_dir = 'data/VOCdevkit/VOC2007/JPEGImages/'
out_dir = 'results/'
if not os.path.exists(out_dir):
os.mkdir(out_dir)
def py_cpu_nms(dets, thresh):
"""Pure Python NMS baseline."""
dets = np