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

相关文章

Spring Boot spring-boot-maven-plugin 参数配置详解(最新推荐)

《SpringBootspring-boot-maven-plugin参数配置详解(最新推荐)》文章介绍了SpringBootMaven插件的5个核心目标(repackage、run、start... 目录一 spring-boot-maven-plugin 插件的5个Goals二 应用场景1 重新打包应用

Linux系统性能检测命令详解

《Linux系统性能检测命令详解》本文介绍了Linux系统常用的监控命令(如top、vmstat、iostat、htop等)及其参数功能,涵盖进程状态、内存使用、磁盘I/O、系统负载等多维度资源监控,... 目录toppsuptimevmstatIOStatiotopslabtophtopdstatnmon

Java内存分配与JVM参数详解(推荐)

《Java内存分配与JVM参数详解(推荐)》本文详解JVM内存结构与参数调整,涵盖堆分代、元空间、GC选择及优化策略,帮助开发者提升性能、避免内存泄漏,本文给大家介绍Java内存分配与JVM参数详解,... 目录引言JVM内存结构JVM参数概述堆内存分配年轻代与老年代调整堆内存大小调整年轻代与老年代比例元空

Spring 框架之Springfox使用详解

《Spring框架之Springfox使用详解》Springfox是Spring框架的API文档工具,集成Swagger规范,自动生成文档并支持多语言/版本,模块化设计便于扩展,但存在版本兼容性、性... 目录核心功能工作原理模块化设计使用示例注意事项优缺点优点缺点总结适用场景建议总结Springfox 是

C++ 检测文件大小和文件传输的方法示例详解

《C++检测文件大小和文件传输的方法示例详解》文章介绍了在C/C++中获取文件大小的三种方法,推荐使用stat()函数,并详细说明了如何设计一次性发送压缩包的结构体及传输流程,包含CRC校验和自动解... 目录检测文件的大小✅ 方法一:使用 stat() 函数(推荐)✅ 用法示例:✅ 方法二:使用 fsee

Python的端到端测试框架SeleniumBase使用解读

《Python的端到端测试框架SeleniumBase使用解读》:本文主要介绍Python的端到端测试框架SeleniumBase使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全... 目录SeleniumBase详细介绍及用法指南什么是 SeleniumBase?SeleniumBase

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