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

相关文章

OpenCV实现实时颜色检测的示例

《OpenCV实现实时颜色检测的示例》本文主要介绍了OpenCV实现实时颜色检测的示例,通过HSV色彩空间转换和色调范围判断实现红黄绿蓝颜色检测,包含视频捕捉、区域标记、颜色分析等功能,具有一定的参考... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间

C++ HTTP框架推荐(特点及优势)

《C++HTTP框架推荐(特点及优势)》:本文主要介绍C++HTTP框架推荐的相关资料,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Crow2. Drogon3. Pistache4. cpp-httplib5. Beast (Boos

SpringBoot基础框架详解

《SpringBoot基础框架详解》SpringBoot开发目的是为了简化Spring应用的创建、运行、调试和部署等,使用SpringBoot可以不用或者只需要很少的Spring配置就可以让企业项目快... 目录SpringBoot基础 – 框架介绍1.SpringBoot介绍1.1 概述1.2 核心功能2

一文详解PostgreSQL复制参数

《一文详解PostgreSQL复制参数》PostgreSQL作为一款功能强大的开源关系型数据库,其复制功能对于构建高可用性系统至关重要,本文给大家详细介绍了PostgreSQL的复制参数,需要的朋友可... 目录一、复制参数基础概念二、核心复制参数深度解析1. max_wal_seChina编程nders:WAL

Linux高并发场景下的网络参数调优实战指南

《Linux高并发场景下的网络参数调优实战指南》在高并发网络服务场景中,Linux内核的默认网络参数往往无法满足需求,导致性能瓶颈、连接超时甚至服务崩溃,本文基于真实案例分析,从参数解读、问题诊断到优... 目录一、问题背景:当并发连接遇上性能瓶颈1.1 案例环境1.2 初始参数分析二、深度诊断:连接状态与

Spring框架中@Lazy延迟加载原理和使用详解

《Spring框架中@Lazy延迟加载原理和使用详解》:本文主要介绍Spring框架中@Lazy延迟加载原理和使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、@Lazy延迟加载原理1.延迟加载原理1.1 @Lazy三种配置方法1.2 @Component

史上最全nginx详细参数配置

《史上最全nginx详细参数配置》Nginx是一个轻量级高性能的HTTP和反向代理服务器,同时也是一个通用代理服务器(TCP/UDP/IMAP/POP3/SMTP),最初由俄罗斯人IgorSyso... 目录基本命令默认配置搭建站点根据文件类型设置过期时间禁止文件缓存防盗链静态文件压缩指定定错误页面跨域问题

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

SpringBoot请求参数接收控制指南分享

《SpringBoot请求参数接收控制指南分享》:本文主要介绍SpringBoot请求参数接收控制指南,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Spring Boot 请求参数接收控制指南1. 概述2. 有注解时参数接收方式对比3. 无注解时接收参数默认位置

Python使用getopt处理命令行参数示例解析(最佳实践)

《Python使用getopt处理命令行参数示例解析(最佳实践)》getopt模块是Python标准库中一个简单但强大的命令行参数处理工具,它特别适合那些需要快速实现基本命令行参数解析的场景,或者需要... 目录为什么需要处理命令行参数?getopt模块基础实际应用示例与其他参数处理方式的比较常见问http