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

相关文章

SpringBoot 获取请求参数的常用注解及用法

《SpringBoot获取请求参数的常用注解及用法》SpringBoot通过@RequestParam、@PathVariable等注解支持从HTTP请求中获取参数,涵盖查询、路径、请求体、头、C... 目录SpringBoot 提供了多种注解来方便地从 HTTP 请求中获取参数以下是主要的注解及其用法:1

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

GSON框架下将百度天气JSON数据转JavaBean

《GSON框架下将百度天气JSON数据转JavaBean》这篇文章主要为大家详细介绍了如何在GSON框架下实现将百度天气JSON数据转JavaBean,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录前言一、百度天气jsON1、请求参数2、返回参数3、属性映射二、GSON属性映射实战1、类对象映

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py

Python脚本轻松实现检测麦克风功能

《Python脚本轻松实现检测麦克风功能》在进行音频处理或开发需要使用麦克风的应用程序时,确保麦克风功能正常是非常重要的,本文将介绍一个简单的Python脚本,能够帮助我们检测本地麦克风的功能,需要的... 目录轻松检测麦克风功能脚本介绍一、python环境准备二、代码解析三、使用方法四、知识扩展轻松检测麦

Go语言使用Gin处理路由参数和查询参数

《Go语言使用Gin处理路由参数和查询参数》在WebAPI开发中,处理路由参数(PathParameter)和查询参数(QueryParameter)是非常常见的需求,下面我们就来看看Go语言... 目录一、路由参数 vs 查询参数二、Gin 获取路由参数和查询参数三、示例代码四、运行与测试1. 测试编程路

解决若依微服务框架启动报错的问题

《解决若依微服务框架启动报错的问题》Invalidboundstatement错误通常由MyBatis映射文件未正确加载或Nacos配置未读取导致,需检查XML的namespace与方法ID是否匹配,... 目录ruoyi-system模块报错报错详情nacos文件目录总结ruoyi-systnGLNYpe

Python lambda函数(匿名函数)、参数类型与递归全解析

《Pythonlambda函数(匿名函数)、参数类型与递归全解析》本文详解Python中lambda匿名函数、灵活参数类型和递归函数三大进阶特性,分别介绍其定义、应用场景及注意事项,助力编写简洁高效... 目录一、lambda 匿名函数:简洁的单行函数1. lambda 的定义与基本用法2. lambda

Python Web框架Flask、Streamlit、FastAPI示例详解

《PythonWeb框架Flask、Streamlit、FastAPI示例详解》本文对比分析了Flask、Streamlit和FastAPI三大PythonWeb框架:Flask轻量灵活适合传统应用... 目录概述Flask详解Flask简介安装和基础配置核心概念路由和视图模板系统数据库集成实际示例Stre

Olingo分析和实践之OData框架核心组件初始化(关键步骤)

《Olingo分析和实践之OData框架核心组件初始化(关键步骤)》ODataSpringBootService通过初始化OData实例和服务元数据,构建框架核心能力与数据模型结构,实现序列化、URI... 目录概述第一步:OData实例创建1.1 OData.newInstance() 详细分析1.1.1