200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > mmdetection中使用训练好的模型单张图片推理并保存到文件夹

mmdetection中使用训练好的模型单张图片推理并保存到文件夹

时间:2019-11-17 10:23:19

相关推荐

mmdetection中使用训练好的模型单张图片推理并保存到文件夹

mmdetection中使用训练好的模型单张图片推理并保存到文件夹

one_image_demo.py

# Copyright (c) OpenMMLab. All rights reserved.import asyncioimport numpy as npfrom argparse import ArgumentParserfrom mmdet.apis import (async_inference_detector, inference_detector,init_detector, show_result_pyplot)import warningswarnings.filterwarnings("ignore") def parse_args():parser = ArgumentParser()parser.add_argument('--img', default='demo.jpg',help='Image file')parser.add_argument('--config',default='../configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py', help='Config file')parser.add_argument('--checkpoint',default='../checkpoints/faster_rcnn_r50_fpn_1x_coco_0130-047c8118.pth', help='Checkpoint file')parser.add_argument('--device', default='cpu', help='Device used for inference') #cuda:0parser.add_argument('--score-thr', type=float, default=0.9, help='bbox score threshold')parser.add_argument('--async-test',action='store_true',help='whether to set async options for async inference.')args = parser.parse_args()return argsdef main(args):model = init_detector(args.config, args.checkpoint, device=args.device)result = inference_detector(model, args.img)#bboxes_scores = np.vstack(result)#bboxes=bboxes_scores[:,:4]#score=bboxes_scores[:,4]#labels = [# np.full(bbox.shape[0], i, dtype=np.int32)# for i, bbox in enumerate(result)# ]#labels = np.concatenate(labels)#print(bboxes_scores)#print(labels)#print(result)model.show_result(args.img,result, score_thr=args.score_thr,out_file='demo_test.jpg')# show the results#show_result_pyplot(model, args.img, result, score_thr=args.score_thr)if __name__ == '__main__':args = parse_args()if args.async_test:asyncio.run(async_main(args))else:main(args)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。