当前位置: 首页 > news >正文

Yolov5 batch 推理

前言

想要就有了

代码

import shutil
import time
import traceback
import torchimport os
import cv2
class PeopleDetect(object):def __init__(self, repo_or_dir, weight_path, confidence) -> None:self.model = torch.hub.load(repo_or_dir, "custom", path=weight_path, source='local',force_reload=True)self.confidence = confidencedef start(self, img) -> list:mode_result = self.model(img,size=640)assert mode_resultdetect_result = mode_result.pandas().xyxy[0].to_dict(orient='index')if (len(detect_result)) > 0:box_list = self._get_box(detect_result)return box_listelse:return []def _get_box(self, detect_result:list) -> list:box_list = []for i in range(len(detect_result)):conf = detect_result[i]['confidence']xmin = int(detect_result[i]['xmin'])ymin = int(detect_result[i]['ymin'])xmax = int(detect_result[i]['xmax'])ymax = int(detect_result[i]['ymax'])if conf > self.confidence:box_list.append([xmin, ymin, xmax, ymax,conf])return box_listdetect=PeopleDetect(repo_or_dir="yolov5", weight_path='weight/best.pt', confidence=0.01)images_path="/home/save_images"
save_path="/home/errors"
Filelist = []
for home, dirs, files in os.walk(images_path):for filename in files:Filelist.append(os.path.join(home, filename))start_time=time.time()
image_list=[]
count=0
for ind,i in enumerate( Filelist):try:image_ori=cv2.imread(i)if len(image_list)<128:image_list.append(image_ori[:,:,-1])else:res=detect.start(image_list)image_list=[]print(int(time.time() - start_time) / int(ind))except (Exception,BaseException)as e:print(traceback.format_exc())

测试结果

以下结果使用RTX3080 测试得出,imgsize为640,model为5s 

batch

GPU显存/MB

单帧耗时/sFPS
115000.0333
816000.0250
1617000.02150
3228000.02150
6436000.018950
10046000.021750
12854000.021850
20074000.02250

http://www.lryc.cn/news/221342.html

相关文章:

  • 【ARFoundation学习笔记】ARFoundation基础(下)
  • 《UML和模式应用(原书第3版)》2024新修订译本部分截图
  • JSP 学生成绩查询管理系统eclipse开发sql数据库serlvet框架bs模式java编程MVC结构
  • 技术分享 | app自动化测试(Android)-- 属性获取与断言
  • flutter实现上拉到底部加载更多数据
  • UE4 Niagara Module Script 初次使用笔记
  • 【Spring Boot 源码学习】JedisConnectionConfiguration 详解
  • 联想服务器-HTTP boot安装Linux系统
  • 容器滚动更新过程中流量无损
  • 深入理解JS中的this
  • rust 基础数据类型
  • ELK极简上手
  • 在 JavaScript 中,变量的作用域是如何确定的?
  • 常见面试题-TCP三次握手四次挥手
  • 前端框架Vue学习 ——(六)Vue组件库Element
  • 第六章:Property-based Testing and Test Oracles
  • react生命周期函数
  • QSqlDatabase使用Sqlite
  • 宝马——使用人工智能制造和驾驶汽车
  • java入门,Map<? extends String, ?>
  • Spring Boot 统一处理功能
  • 香港金融科技周VERTU CSO Sophie谈Web3.0的下一个风口 手机虚拟货币移动支付
  • 分布式单元化
  • wvp-gb28181-pro接入海康摄像头
  • 近视眼选择什么台灯好?专家推荐的防近视台灯
  • 数据标注工具【LabelImg】安装使用 用VOC制作自己的数据集
  • Zeus IoT : 基于 SpringBoot 的分布式开源物联网大数据平台
  • 面试—如何介绍项目中的多级缓存?
  • PyTorch入门学习(十七):完整的模型训练套路
  • 《 Hello 算法 》 - 免费开源的数据结构与算法入门教程电子书,包含大量动画、图解,通俗易懂