网站开发策划方案知乎,优秀网站管理员,淮上网站建设,能进网站的浏览器这个是用demo这个代码测试的#xff0c;需要先训练一个pth文件夹#xff0c;训练之后再调用pth文件夹进行测试。测试的代码文件名是#xff1a;image_demo_new.py#xff0c;代码如系所示#xff1a;
# Copyright (c) OpenMMLab. All rights reserved.
import asyncio
fr…这个是用demo这个代码测试的需要先训练一个pth文件夹训练之后再调用pth文件夹进行测试。测试的代码文件名是image_demo_new.py代码如系所示
# Copyright (c) OpenMMLab. All rights reserved.
import asyncio
from argparse import ArgumentParserfrom mmdet.apis import (async_inference_detector, inference_detector,init_detector, show_result_pyplot)
import cv2
import osdef parse_args():parser ArgumentParser()parser.add_argument(img, defaultNone,helpImage file)parser.add_argument(config, helpConfig file)parser.add_argument(checkpoint, helpCheckpoint file)parser.add_argument(--out-file, defaultNone, helpPath to output file)parser.add_argument(--device, defaultcuda:0, helpDevice used for inference)parser.add_argument(--palette,defaultcoco,choices[coco, voc, citys, random],helpColor palette used for visualization)parser.add_argument(--score-thr, typefloat, default0.3, helpbbox score threshold)parser.add_argument(--async-test,actionstore_true,helpwhether to set async options for async inference.)args parser.parse_args()return argsdef main(args):outdir./demo_out1imgdir./image/firefor imgf in os.listdir(imgdir):if not imgf.endswith(jpg):continue# build the model from a config file and a checkpoint filemodel init_detector(args.config, args.checkpoint, deviceargs.device)# test a single imageresult inference_detector(model, imgdir / imgf)# import pdb;pdb.set_trace()if hasattr(model, module):model model.moduleimg model.show_result(imgdir / imgf,result,score_thrargs.score_thr,showFalse)cv2.imwrite({}/{}.format(outdir,imgf),img)if __name__ __main__:args parse_args()main(args)
记得自己新建“demo_out1”这个文件夹 测试完成之后会保存到一个新的文件夹下面文件名是demo_out1测试代码文件夹名称是 imgdir./image/fire运行的代码如下所示python demo/image_demo_new.py image/fire/image_733.jpg configs/ddod_log_ddod_r50_fpn_1x_coco/ddod_r50_fpn_1x_coco.py configs/ddod_log_ddod_r50_fpn_1x_coco/epoch_100.pth --device cpu
测试我是直接用cpu的没用GPU,界面截图如下所示