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

yolov8 bytetrack onnx模型推理

原文:yolov8 bytetrack onnx模型推理 - 知乎 (zhihu.com)

一、pt模型转onnx

from ultralytics import YOLO# Load a model
model = YOLO('weights/yolov8s.pt')  # load an official model
# model = YOLO('path/to/best.pt')  # load a custom trained# Export the model
model.export(format='onnx')

二、模型预测

import onnxruntime as rt
import numpy as np
import cv2
import matplotlib.pyplot as pltfrom utils.visualize import plot_tracking
from tracker.byte_tracker import BYTETracker
from tracking_utils.timer import TimerCLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light','fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow','elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee','skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard','tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple','sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch','potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone','microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear','hair drier', 'toothbrush']def nms(pred, conf_thres, iou_thres):conf = pred[..., 4] > conf_thresbox = pred[conf == True]cls_conf = box[..., 5:]cls = []for i in range(len(cls_conf)):cls.append(int(np.argmax(cls_conf[i])))total_cls = list(set(cls))output_box = []for i in range(len(total_cls)):clss = total_cls[i]cls_box = []for j in range(len(cls)):if cls[j] == clss:box[j][5] = clsscls_box.append(box[j][:6])cls_box = np.array(cls_box)box_conf = cls_box[..., 4]box_conf_sort = np.argsort(box_conf)max_conf_box = cls_box[box_conf_sort[len(box_conf) - 1]]output_box.append(max_conf_box)cls_box = np.delete(cls_box, 0, 0)while len(cls_box) > 0:max_conf_box = output_box[len(output_box) - 1]del_index = []for j in range(len(cls_box)):current_box = cls_box[j]interArea = getInter(max_conf_box, current_box)iou = getIou(max_conf_box, current_box, interArea)if iou > iou_thres:del_index.append(j)cls_box = np.delete(cls_box, del_index, 0)if len(cls_box) > 0:output_box.append(cls_box[0])cls_box = np.delete(cls_box, 0, 0)return output_boxdef getIou(box1, box2, inter_area):box1_area = box1[2] * box1[3]box2_area = box2[2] * box2[3]union = box1_area + box2_area - inter_areaiou = inter_area / unionreturn ioudef getInter(box1, box2):box1_x1, box1_y1, box1_x2, box1_y2 = box1[0] - box1[2] / 2, box1[1] - box1[3] / 2, \box1[0] + box1[2] / 2, box1[1] + box1[3] / 2box2_x1, box2_y1, box2_x2, box2_y2 = box2[0] - box2[2] / 2, box2[1] - box1[3] / 2, \box2[0] + box2[2] / 2, box2[1] + box2[3] / 2if box1_x1 > box2_x2 or box1_x2 < box2_x1:return 0if box1_y1 > box2_y2 or box1_y2 < box2_y1:return 0x_list = [box1_x1, box1_x2, box2_x1, box2_x2]x_list = np.sort(x_list)x_inter = x_list[2] - x_list[1]y_list = [box1_y1, box1_y2, box2_y1, box2_y2]y_list = np.sort(y_list)y_inter = y_list[2] - y_list[1]inter = x_inter * y_interreturn interdef draw(img, xscale, yscale, pred):# img_ = img.copy()if len(pred):for detect in pred:box = [int((detect[0] - detect[2] / 2) * xscale), int((detect[1] - detect[3] / 2) * yscale),int((detect[0] + detect[2] / 2) * xscale), int((detect[1] + detect[3] / 2) * yscale)]cv2.rectangle(img, (box[0], box[1]), (box[2], box[3]), (0, 255, 0), 1)font = cv2.FONT_HERSHEY_SCRIPT_SIMPLEXcv2.putText(img, 'class: {}, conf: {:.2f}'.format( CLASSES[int(detect[5])], detect[4]), (box[0], box[1]),font, 0.7, (255, 0, 0), 2)return imgif __name__ == '__main__':height, width = 640, 640cap = cv2.VideoCapture('../../demo/test_person.mp4')while True:# t0 = time.time()# if frame_id % 20 == 0:#     logger.info('Processing frame {} ({:.2f} fps)'.format(frame_id, 1. / max(1e-5, timer.average_time)))ret_val, frame = cap.read()if ret_val:# img0 = cv2.imread('test.jpg')img0 = framex_scale = img0.shape[1] / widthy_scale = img0.shape[0] / heightimg = img0 / 255.img = cv2.resize(img, (width, height))img = np.transpose(img, (2, 0, 1))data = np.expand_dims(img, axis=0)print(data.shape)sess = rt.InferenceSession('weights/yolov8n.onnx')input_name = sess.get_inputs()[0].namelabel_name = sess.get_outputs()[0].nameprint(input_name, label_name)# print(sess.run([label_name], {input_name: data.astype(np.float32)}))pred = sess.run([label_name], {input_name: data.astype(np.float32)})[0]# print(pred.shape)  # (1, 84, 8400)pred = np.squeeze(pred)pred = np.transpose(pred, (1, 0))pred_class = pred[..., 4:]# print(pred_class)pred_conf = np.max(pred_class, axis=-1)pred = np.insert(pred, 4, pred_conf, axis=-1)result = nms(pred, 0.3, 0.45)# print(result[0].shape)# bboxes = []# scores = []## # print(result)## for detect in result:#     box = [int((detect[0] - detect[2] / 2) * x_scale), int((detect[1] - detect[3] / 2) * y_scale),#            int((detect[0] + detect[2] / 2) * x_scale), int((detect[1] + detect[3] / 2) * y_scale)]##     bboxes.append(box)#     score = detect[4]#     scores.append(score)# print(result)ret_img = draw(img0, x_scale, y_scale, result)# ret_img = ret_img[:, :, ::-1]# plt.imshow(ret_img)# plt.show()cv2.imshow("frame", ret_img)# vid_writer.write(online_im)ch = cv2.waitKey(1)if ch == 27 or ch == ord("q") or ch == ord("Q"):break# online_targets = tracker.update(bboxes, scores)# online_tlwhs = []# online_ids = []# online_scores = []# for i, t in enumerate(online_targets):#     # tlwh = t.tlwh#     tlwh = t.tlwh_yolox#     tid = t.track_id#     # vertical = tlwh[2] / tlwh[3] > args.aspect_ratio_thresh#     # if tlwh[2] * tlwh[3] > args.min_box_area and not vertical:#     if tlwh[2] * tlwh[3] > args.min_box_area:#         online_tlwhs.append(tlwh)#         online_ids.append(tid)#         online_scores.append(t.score)#         results.append(#             f"{frame_id},{tid},{tlwh[0]:.2f},{tlwh[1]:.2f},{tlwh[2]:.2f},{tlwh[3]:.2f},{t.score:.2f},-1,-1,-1\n"#         )# t1 = time.time()# time_ = (t1 - t0) * 1000## online_im = plot_tracking(frame, online_tlwhs, online_ids, frame_id=frame_id + 1,#                           fps=1000. / time_)## cv2.imshow("frame", online_im)## # vid_writer.write(online_im)# ch = cv2.waitKey(1)# if ch == 27 or ch == ord("q") or ch == ord("Q"):#     breakelse:break# frame_id += 1

视频见原文。 

相关文章:

yolov8 bytetrack onnx模型推理

原文&#xff1a;yolov8 bytetrack onnx模型推理 - 知乎 (zhihu.com) 一、pt模型转onnx from ultralytics import YOLO# Load a model model YOLO(weights/yolov8s.pt) # load an official model # model YOLO(path/to/best.pt) # load a custom trained# Export the mod…...

ImageNet数据集和CIFAR-10数据集

一、为什么需要大量数据集 人工智能其实就是大数据的时代&#xff0c;无论是目标检测、图像分类、还是现在植入我们生活的推荐系统&#xff0c;“喂入”神经网络的数据越多&#xff0c;则识别效果越好、分类越准确。因此开源大型数据集的研究团队为人工智能的发展做了大量贡献…...

Go语言编程大全,web微服务数据库十大专题精讲

本课程主要从数据结构、Go Module 依赖管理、IO编程、数据库编程、消息队列、加密技术与网络安全、爬虫与反爬虫、web开发、微服务通用技术、Kitex框架等方面讲解~ 链接&#xff1a;https://pan.quark.cn/s/d65337a0e60d...

【LabVIEW学习篇 - 13】:队列

文章目录 队列 队列 队列通常情况下是一种先入先出&#xff08;FIFO&#xff1a;First in First out&#xff09;的数据结构&#xff0c;常用作数据缓存&#xff0c;通过队列结构可以保证数据有序的传递&#xff0c;避免竞争和冲突。 案例&#xff1a;利用队列&#xff0c;模…...

大语言模型综述泛读之Large Language Models: A Survey

摘要 这篇文章主要回顾了一些最突出的LLMs(GPT, LLaMA, PaLM)并讨论了它们的特点、贡献和局限性,就如何构建增强LLMs做了一个技术概述,然后调研了为LLM训练、微调和评估而准备的N多种流行数据集,审查了使用的LLM评价指标,在一组有代表性的基准上比较了几个流行的LLMs;最…...

奇偶函数的性质及运算

目录 定义 注意 特征 运算 拓展 定义 设函数f(x)的定义域D&#xff1b; 如果对于函数定义域D内的任意一个x&#xff0c;都有f(-x)&#xff0d;f&#xff08;x&#xff09;&#xff0c;那么函数f&#xff08;x&#xff09;就叫做奇函数。如果对于函数定义域D内的任意一个x…...

代码随想录 day 32 动态规划

第九章 动态规划part01 今天正式开始动态规划&#xff01; 理论基础 无论大家之前对动态规划学到什么程度&#xff0c;一定要先看 我讲的 动态规划理论基础。 如果没做过动态规划的题目&#xff0c;看我讲的理论基础&#xff0c;会有感觉 是不是简单题想复杂了&#xff1f; …...

支持目标检测的框架有哪些

目标检测是计算机视觉领域的一个重要任务&#xff0c;许多深度学习框架都提供了对目标检测的支持。以下是一些广泛使用的支持目标检测的深度学习框架&#xff1a; 1. TensorFlow TensorFlow 是一个广泛使用的开源深度学习框架&#xff0c;由Google开发。它提供了TensorFlow O…...

原神自定义倒计时

<!DOCTYPE html> <html lang"zh-CN"><head><meta charset"UTF-8"><title>原神倒计时</title><style>* {margin: 0;padding: 0;box-sizing: border-box;user-select: none;body {background: #0b1b2c;}}header {…...

top命令实时监测Linux进程

top命令可以动态实时显示Linux进程信息&#xff0c;方便观察频繁换进换出的内存的进程变化。 top命令执行示例如下&#xff1a; 其中&#xff0c;第一行表示系统当前时间、系统的运行时间、登录的用户数目、系统的平均负载&#xff08;最近1分钟&#xff0c;最近5分钟&#xff…...

Rust 所有权

所有权 Rust的核心特性就是所有权所有程序在运行时都必须管理他们使用计算机内存的方式 有些语言有垃圾收集机制&#xff0c;在程序运行时&#xff0c;他们会不断地寻找不再使用的内存在其他语言中&#xff0c;程序员必须显式的分配和释放内存 Rust采用了第三种方式&#xff1…...

Python面试题:结合Python技术,如何使用PyTorch进行动态计算图构建

PyTorch 是一个流行的深度学习框架&#xff0c;它通过动态计算图&#xff08;Dynamic Computation Graphs&#xff09;来支持自动微分&#xff08;Autograd&#xff09;。动态计算图的特点是每次前向传播时都会构建新的计算图&#xff0c;这使得它非常灵活&#xff0c;适合处理…...

基于RHEL7的服务器批量安装

目录 一、项目要求 二、实验环境 三、生成kickstart自动化安装脚本 四、搭建dhcp服务并测试kickstart脚本 五、搭建pxe网络安装环境实现服务器自动部署 ​编辑 六、测试 一、项目要求 1.使用kickstart编写自动化安装脚本 2.搭建dhcp服务并测试kickstart脚本 3.搭建px…...

C. Light Switches

文章目录 C. Light Switches题意&#xff1a;解题思路&#xff1a;解题代码&#xff1a; C. Light Switches 原题链接 题意&#xff1a; 房间的灯最初均为关闭状态&#xff0c;安装芯片后&#xff0c;它会每隔k分钟改变一次房间的灯光状态&#xff0c;即会打开灯光k分钟&…...

LabVIEW机器人神经网络运动控制系统

LabVIEW机器人神经网络运动控制系统 介绍了如何使用LabVIEW软件和中枢模式发生器(CPG)神经网络实现对舵机驱动爬壁机器人的精准运动控制。通过结合仿生控制理念与高级程序设计&#xff0c;本项目旨在开发一种能自动完成复杂墙面移动任务的机器人。 项目背景 现代机器人技术中…...

Qt WebEngine播放DRM音视频

Qt WebEngine播放DRM受保护视频&#xff0c;前提是Qt WebEngine开启音视频编码器&#xff0c;能够支持网页上普通视频的播放。开启音视频编码器需要自己编译源码&#xff0c;这里不做介绍。 什么是DRM音视频 DRM视频是指数字版权管理&#xff08;Digital Rights Management&a…...

渗透小游戏,各个关卡的渗透实例

Less-1 首先&#xff0c;可以看见该界面&#xff0c;该关卡主要是SQL注入&#xff0c;由于对用户的输入没有做过滤&#xff0c;使查询语句进入到了数据库中&#xff0c;查询到了本不应该查询到的数据 首先&#xff0c;如果想要进入内部&#xff0c;就要绕过&#xff0c;首先是用…...

SpringBoot集成阿里百炼大模型(初始demo) 原子的学习日记Day01

文章目录 概要下一章SpringBoot集成阿里百炼大模型&#xff08;多轮对话&#xff09; 原子的学习日记Day02 整体架构流程技术名词解释集成步骤1&#xff0c;选择大模型以及获取自己的api-key&#xff08;前面还有一步开通服务就没有展示啦&#xff01;&#xff09;2&#xff0c…...

高级java每日一道面试题-2024年8月06日-web篇-cookie,session,token有什么区别?

如果有遗漏,评论区告诉我进行补充 面试官: cookie,session,token有什么区别? 我回答: 在Web开发中&#xff0c;cookie、session和token是三种常见的用于用户身份验证和会话管理的技术。它们各自有不同的用途和优缺点&#xff0c;下面将详细解释&#xff1a; 1. Cookie 定…...

Python 图文:小白也能轻松生成精美 PDF 报告!

摘要: 还在为枯燥的数据报表发愁吗&#xff1f;想让你的 Python 项目报告瞬间高大上&#xff1f;本文将带你学习如何使用 Python 生成图文并茂的 PDF 文件&#xff0c;从此告别单调&#xff0c;让你的数据“活”起来&#xff01; 一、 引言 想象一下&#xff0c;你正在为公司…...

《Qt C++ 与 OpenCV:解锁视频播放程序设计的奥秘》

引言:探索视频播放程序设计之旅 在当今数字化时代,多媒体应用已渗透到我们生活的方方面面,从日常的视频娱乐到专业的视频监控、视频会议系统,视频播放程序作为多媒体应用的核心组成部分,扮演着至关重要的角色。无论是在个人电脑、移动设备还是智能电视等平台上,用户都期望…...

【SpringBoot】100、SpringBoot中使用自定义注解+AOP实现参数自动解密

在实际项目中,用户注册、登录、修改密码等操作,都涉及到参数传输安全问题。所以我们需要在前端对账户、密码等敏感信息加密传输,在后端接收到数据后能自动解密。 1、引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId...

spring:实例工厂方法获取bean

spring处理使用静态工厂方法获取bean实例&#xff0c;也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下&#xff1a; 定义实例工厂类&#xff08;Java代码&#xff09;&#xff0c;定义实例工厂&#xff08;xml&#xff09;&#xff0c;定义调用实例工厂&#xff…...

Qt Http Server模块功能及架构

Qt Http Server 是 Qt 6.0 中引入的一个新模块&#xff0c;它提供了一个轻量级的 HTTP 服务器实现&#xff0c;主要用于构建基于 HTTP 的应用程序和服务。 功能介绍&#xff1a; 主要功能 HTTP服务器功能&#xff1a; 支持 HTTP/1.1 协议 简单的请求/响应处理模型 支持 GET…...

Spring Boot面试题精选汇总

&#x1f91f;致敬读者 &#x1f7e9;感谢阅读&#x1f7e6;笑口常开&#x1f7ea;生日快乐⬛早点睡觉 &#x1f4d8;博主相关 &#x1f7e7;博主信息&#x1f7e8;博客首页&#x1f7eb;专栏推荐&#x1f7e5;活动信息 文章目录 Spring Boot面试题精选汇总⚙️ **一、核心概…...

解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错

出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上&#xff0c;所以报错&#xff0c;到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本&#xff0c;cu、torch、cp 的版本一定要对…...

IoT/HCIP实验-3/LiteOS操作系统内核实验(任务、内存、信号量、CMSIS..)

文章目录 概述HelloWorld 工程C/C配置编译器主配置Makefile脚本烧录器主配置运行结果程序调用栈 任务管理实验实验结果osal 系统适配层osal_task_create 其他实验实验源码内存管理实验互斥锁实验信号量实验 CMISIS接口实验还是得JlINKCMSIS 简介LiteOS->CMSIS任务间消息交互…...

用docker来安装部署freeswitch记录

今天刚才测试一个callcenter的项目&#xff0c;所以尝试安装freeswitch 1、使用轩辕镜像 - 中国开发者首选的专业 Docker 镜像加速服务平台 编辑下面/etc/docker/daemon.json文件为 {"registry-mirrors": ["https://docker.xuanyuan.me"] }同时可以进入轩…...

Linux --进程控制

本文从以下五个方面来初步认识进程控制&#xff1a; 目录 进程创建 进程终止 进程等待 进程替换 模拟实现一个微型shell 进程创建 在Linux系统中我们可以在一个进程使用系统调用fork()来创建子进程&#xff0c;创建出来的进程就是子进程&#xff0c;原来的进程为父进程。…...

LeetCode - 199. 二叉树的右视图

题目 199. 二叉树的右视图 - 力扣&#xff08;LeetCode&#xff09; 思路 右视图是指从树的右侧看&#xff0c;对于每一层&#xff0c;只能看到该层最右边的节点。实现思路是&#xff1a; 使用深度优先搜索(DFS)按照"根-右-左"的顺序遍历树记录每个节点的深度对于…...