MMDetection目标检测框架推理与参数量计算

2024-05-04 18:52

本文主要是介绍MMDetection目标检测框架推理与参数量计算,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

模型推理

在使用MMDetection框架完成训练后便可以使用训练所得的权重文件进行推理了,具体可以使用MMDetection文件下的demo文件夹的image_demo.py文件。

from argparse import ArgumentParser
from mmengine.logging import print_log
from mmdet.apis import DetInferencerdef parse_args():parser = ArgumentParser()parser.add_argument('--inputs', type=str,default="/home/ubuntu/programs/mmdetection/tools/images/4.jpg", help='Input image file or folder path.')parser.add_argument('--model',type=str,default="/home/ubuntu/programs/mmdetection/output/faster-rcnn_r50_fpn_2x_coco.py",help='Config or checkpoint .pth file or the model name ''and alias defined in metafile. The model configuration ''file will try to read from .pth if the parameter is ''a .pth weights file.')parser.add_argument('--weights', default="/home/ubuntu/programs/mmdetection/output//epoch_24.pth", help='Checkpoint file')parser.add_argument('--out-dir',type=str,default='/home/ubuntu/programs/mmdetection/outputs/',help='Output directory of images or prediction results.')parser.add_argument('--texts', help='text prompt')parser.add_argument('--device', default='cpu', help='Device used for inference')parser.add_argument('--pred-score-thr',type=float,default=0.5,help='bbox score threshold')parser.add_argument('--batch-size', type=int, default=1, help='Inference batch size.')parser.add_argument('--show',action='store_true',help='Display the image in a popup window.')parser.add_argument('--no-save-vis',action='store_true',help='Do not save detection vis results')parser.add_argument('--no-save-pred',action='store_true',help='Do not save detection json results')parser.add_argument('--print-result',action='store_true',help='Whether to print the results.')parser.add_argument('--palette',default='none',choices=['coco', 'voc', 'citys', 'random', 'none'],help='Color palette used for visualization')# only for GLIPparser.add_argument('--custom-entities','-c',action='store_true',help='Whether to customize entity names? ''If so, the input text should be ''"cls_name1 . cls_name2 . cls_name3 ." format')call_args = vars(parser.parse_args())if call_args['no_save_vis'] and call_args['no_save_pred']:call_args['out_dir'] = ''if call_args['model'].endswith('.pth'):print_log('The model is a weight file, automatically ''assign the model to --weights')call_args['weights'] = call_args['model']call_args['model'] = Noneinit_kws = ['model', 'weights', 'device', 'palette']init_args = {}for init_kw in init_kws:init_args[init_kw] = call_args.pop(init_kw)return init_args, call_argsdef main():init_args, call_args = parse_args()inferencer = DetInferencer(**init_args)inferencer(**call_args)if call_args['out_dir'] != '' and not (call_args['no_save_vis']and call_args['no_save_pred']):print_log(f'results have been saved at {call_args["out_dir"]}')
if __name__ == '__main__':main()

在这里插入图片描述

参数量与计算量

关于参数量与flops的计算可以使用tools/analysis_tools/get_flops.py,这里就不再赘述了。

这篇关于MMDetection目标检测框架推理与参数量计算的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/959877

相关文章

Python如何实现PDF隐私信息检测

《Python如何实现PDF隐私信息检测》随着越来越多的个人信息以电子形式存储和传输,确保这些信息的安全至关重要,本文将介绍如何使用Python检测PDF文件中的隐私信息,需要的可以参考下... 目录项目背景技术栈代码解析功能说明运行结php果在当今,数据隐私保护变得尤为重要。随着越来越多的个人信息以电子形

修改若依框架Token的过期时间问题

《修改若依框架Token的过期时间问题》本文介绍了如何修改若依框架中Token的过期时间,通过修改`application.yml`文件中的配置来实现,默认单位为分钟,希望此经验对大家有所帮助,也欢迎... 目录修改若依框架Token的过期时间修改Token的过期时间关闭Token的过期时js间总结修改若依

Java通过反射获取方法参数名的方式小结

《Java通过反射获取方法参数名的方式小结》这篇文章主要为大家详细介绍了Java如何通过反射获取方法参数名的方式,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、前言2、解决方式方式2.1: 添加编译参数配置 -parameters方式2.2: 使用Spring的内部工具类 -

Python调用另一个py文件并传递参数常见的方法及其应用场景

《Python调用另一个py文件并传递参数常见的方法及其应用场景》:本文主要介绍在Python中调用另一个py文件并传递参数的几种常见方法,包括使用import语句、exec函数、subproce... 目录前言1. 使用import语句1.1 基本用法1.2 导入特定函数1.3 处理文件路径2. 使用ex

SpringBoot使用Apache Tika检测敏感信息

《SpringBoot使用ApacheTika检测敏感信息》ApacheTika是一个功能强大的内容分析工具,它能够从多种文件格式中提取文本、元数据以及其他结构化信息,下面我们来看看如何使用Ap... 目录Tika 主要特性1. 多格式支持2. 自动文件类型检测3. 文本和元数据提取4. 支持 OCR(光学

MySQL中时区参数time_zone解读

《MySQL中时区参数time_zone解读》MySQL时区参数time_zone用于控制系统函数和字段的DEFAULTCURRENT_TIMESTAMP属性,修改时区可能会影响timestamp类型... 目录前言1.时区参数影响2.如何设置3.字段类型选择总结前言mysql 时区参数 time_zon

Python如何使用seleniumwire接管Chrome查看控制台中参数

《Python如何使用seleniumwire接管Chrome查看控制台中参数》文章介绍了如何使用Python的seleniumwire库来接管Chrome浏览器,并通过控制台查看接口参数,本文给大家... 1、cmd打开控制台,启动谷歌并制定端口号,找不到文件的加环境变量chrome.exe --rem

Linux中Curl参数详解实践应用

《Linux中Curl参数详解实践应用》在现代网络开发和运维工作中,curl命令是一个不可或缺的工具,它是一个利用URL语法在命令行下工作的文件传输工具,支持多种协议,如HTTP、HTTPS、FTP等... 目录引言一、基础请求参数1. -X 或 --request2. -d 或 --data3. -H 或

如何用Java结合经纬度位置计算目标点的日出日落时间详解

《如何用Java结合经纬度位置计算目标点的日出日落时间详解》这篇文章主详细讲解了如何基于目标点的经纬度计算日出日落时间,提供了在线API和Java库两种计算方法,并通过实际案例展示了其应用,需要的朋友... 目录前言一、应用示例1、天安门升旗时间2、湖南省日出日落信息二、Java日出日落计算1、在线API2

详解Spring Boot接收参数的19种方式

《详解SpringBoot接收参数的19种方式》SpringBoot提供了多种注解来接收不同类型的参数,本文给大家介绍SpringBoot接收参数的19种方式,感兴趣的朋友跟随小编一起看看吧... 目录SpringBoot接受参数相关@PathVariable注解@RequestHeader注解@Reque