用mmdetection测试推理多张图片并保存

# Copyright (c) OpenMMLab. All rights reserved.
import asyncio
from argparse import ArgumentParser

from mmdet.apis import (async_inference_detector, inference_detector,
                        init_detector, show_result_pyplot)
import os
import tqdm


def parse_args():
    parser = ArgumentParser()
    parser.add_argument('--img', default='G:/A_Data/VOC2012/val_image', help='Image file')
    parser.add_argument('--config', default='G:/mmdetection-master-5-8/soft_nms.py', help='Config file')
    parser.add_argument('--checkpoint', default='G:/mmdetection-master-5-8/best_mAP_epoch_9.pth', help='Checkpoint file')
    parser.add_argument('--out-file', default='G:/mmdetection-master-5-8/results/oft', help='Path to output file')
    parser.add_argument('--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--palette',
        default='voc',
        choices=['coco', 'voc', 'citys', 'random'],
        help='Color palette used for visualization')
    parser.add_argument('--score-thr', type=float, default=0.3, help='bbox score threshold')
    args = parser.parse_args()
    return args


def main(args):
    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)

    for filename in tqdm.tqdm(os.listdir(args.img)):
        img = os.path.join(args.img, filename)
        result = inference_detector(model, img)
        out_file = os.path.join(args.out_file, filename)
        show_result_pyplot(
            model,
            img,
            result,
            palette=args.palette,
            score_thr=args.score_thr,
            out_file=out_file)


if __name__ == '__main__':
    args = parse_args()
    main(args)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值