mmdetection使用记录

mmdetection使用记录


mmdetection使用记录

1.根据自己使用的数据,修改configs下的文件,num_classes=(数据类别数+1)
注:有些文件有一处,有些有多处
2.训练:python tools/train.py configs/mask_rcnn_r50_fpn_1x.py
3.测试:python tools/test.py configs/mask_rcnn_r50_fpn_1x.py work_dirs/mask_rcnn_r50_fpn_1x/latest.pth --out results.pkl --show
注:–show会显示结果图像;–out results.pkl保存结果文件;–eval bbox会报错
4.验证: python tools/voc_eval.py results.pkl configs/faster_rcnn_r50_fpn_1x.py
注:若想计算mAP,测试阶段不能–show,否则结果会出问题

附:demo.py,能够查看并保存模型检测结果

np.set_printoptions(suppress=True)
# 模型配置文件
config_file = './configs/faster_rcnn_r50_fpn_1x.py'
# 预训练模型文件
checkpoint_file = './work_dirs/faster_rcnn_r50_fpn_1x/epoch_12.pth'
# 测试单张图片并进行展示
# img = '/home/work/mmdet1.0rc/mmdetection-1.0rc0/data/coco1/val2017/0L3_000_E_6.jpg'
img_path = './data2/coco/val2017/'
# 结果保存路径
savepath = './results/'

# 通过模型配置文件与预训练文件构建模型
model = init_detector(config_file, checkpoint_file, device='cuda:0')
img_list = sorted(glob.glob(os.path.join(img_path + '*.jpg')))

f = open('results.txt', 'w')
f.write(str(model.CLASSES) + '\n')

for img in img_list:
    f.write(img.split('/')[-1] + '\n')
    result = inference_detector(model, img)
    for i in range(len(model.CLASSES)):
        # f.write(model.CLASSES[i] + '\n' + str(result[0][i]) + '\n')   #mask + coco
        f.write(model.CLASSES[i] + '\n' + str(result[i]) + '\n')        #voc格式
    # f.write(str(result) + '\n')
    save_img = savepath + img.split('/')[-1]
    show_result(img, result, model.CLASSES, out_file = save_img)
f.close()

同时,将./mmdet/apis/inference.py中

你可能感兴趣的:(mmdet使用,pytorch,深度学习,python)