mmdetection # test and visualize test result

  1. evaluation,这里没有保存结果,但是可以show一下。
tools/dist_test.sh configs/swin/cascade_mask_rcnn_swin_base_patch4_window7_mstrain_480-800_giou_4conv1f_adamw_3x_coco.py latest.pth 1 --eval bbox segm
  1. save result
    refer to demo/image_demo.py

(1) edit mmdet/apis/inference.py 在函数show_result_pyplot中,加上"model.show_result(img, result, out_file=out_file)" 保存测试结果。

def show_result_pyplot(model,
                       img,
                       result,
                       out_file,
                       score_thr=0.3,
                       title='result',
                       wait_time=0):
    #Visualize the detection results on the image.
    if hasattr(model, 'module'):
        model = model.module
    
    model.show_result(
        img,
        result,
        score_thr=score_thr,
        show=True,
        wait_time=wait_time,
        win_name=title,
        bbox_color=(72, 101, 241),
        text_color=(72, 101, 241))

    model.show_result(img, result, out_file=out_file)

(2) test and save test result as image

run image_demo.py:

import os
from argparse import ArgumentParser
from mmdet.apis import inference_detector, init_detector, show_result_pyplot

def main():
    
    checkpointfile = './work_dirs/cascade_mask_rcnn_swin_base_patch4_window7_mstrain_480-800_giou_4conv1f_adamw_3x_coco/latest.pth'  
    configfile = './configs/swin/cascade_mask_rcnn_swin_base_patch4_window7_mstrain_480-800_giou_4conv1f_adamw_3x_coco.py'
    score_thr = 0.3

    # build the model from a config file and a checkpoint file
    model = init_detector(configfile, checkpointfile, device='cuda:0')
    

    imgfolder = './data/coco/test2017/JPEGImages/'
    savefolder = './result/'

    for imgfile in os.listdir(imgfolder):
        img = imgfolder + imgfile
        out_file = savefolder + 're_' + imgfile

        # test a single image
        result = inference_detector(model, img)
        # show the results
        show_result_pyplot(model, img, result, out_file, score_thr = score_thr)
        
if __name__ == '__main__':
    main()

(3) 修改bbox和label格式,mmdet/core/visualization/image.py

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值