current position:Home>Target tracking actual combat deepsort+yolov5 (on)

Target tracking actual combat deepsort+yolov5 (on)

2022-08-06 18:09:39the_way_inf

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第4天,点击查看活动详情 >>

前言

The main purpose of today is to quickly get started with target tracking,In the previous words, I briefly talked about the Kalman filter,Then due to blogging issues,Not finished.I wanted to do a series,But it's hard to sort out,And to be honest, there are some things I don't understand.当然这并不影响我们使用,Abstract to continuehappy,Like you don't understandSpringBoot 或者Django底层一样,Still wide enough to make a website.

算法简介

First of all, what we are talking about here is actually the whole project,是两个部分,One is the tracking part of the target,There is also the recognition and detection part of the target.We need to detect an item first,We can follow,At the same time, this algorithm is also based on the target detection algorithm.

The relationship between them is like this:

在这里插入图片描述 Then there is not much to say about target detection here.

You can refer to these blog posts:

GitHub 水项目之 快速上手 YOLOV5

YOLOV5 参数设定与模型训练的坑点一二三

YOLOV1Small finishing of the thesis and this blog post: Teach you how to make your own target detection framework(从理论到实现)

So we are mainly heredeepsort的一个情况.

sort算法

Speaking of this stuff, I have to talk about it firstsort算法.

Earlier when talking about the list tracking,我们说到了卡尔曼滤波 But this just solves a problem,It is the position where we predict that the next box of the modified object may exist,After that we calculate someIOUMake sure that this next box is our target object,So as to determine his trajectory to complete the target tracking.

But what we assumed earlier was a single-objective case,If it is multi-target,It also involves the question of how to assign a tracked target.That is, give the target a different label,Then recognize after predicting his trajectory,Determine which target this trajectory is for.

所以这个sortThe algorithm actually has two parts,That is, in order to complete one of our target tracking.

一个是匈牙利算法,The purpose is to determine who is who,One is that Kalman tracks in order to predict a state of the object.

在这里插入图片描述

deepsort

deepsort 是在sortA lot of other work is done on the basis of the algorithm.

由于sortThe algorithm is still a rough tracking algorithm,When an object is occluded,Especially easy to lose your ownID.而Deepsort算法在sort算法的基础上增加了级联匹配(MatchingCascade)和新轨迹的确认(confirmed).TracksDivided into confirmation state(confirmed),and indeterminate state(unconfirmed),新产生的Tracksis indeterminate:UnconfirmedTracks必须要和DetectionsMatch a certain number of times in a row(默认是3)can be converted into a confirmed state.ConfirmedTracks必须和DetectionsiA certain number of consecutive mismatches(默认30次),才会被删除.

Then his algorithm flow is probably like this: (Know the picture of the big guy) 在这里插入图片描述

项目结构

Our words here today,Let's do a brief introduction first,After that, let's be like beforeyoloSame as how to train your own model,Then complete one of your needs.

在这里插入图片描述

We focus on seeing this firstdeep_sort 在这里插入图片描述 Here I first give a description of these parameters.

(1)It contains the directory path of the feature extraction weights;

(2)最大余弦距离,用于级联匹配,如果大于该阈值,则忽略.

(3)检测结果置信度阈值

(4)非极大抑制阈值,设置为1代表不进行抑制

(5)最大IOU阈值

(6)最大寿命,也就是经过MAX_AGE帧没有追踪到该物体,就将该轨迹变为删除态.

(7)最高击中次数,如果击中该次数,就由不确定态转为确定态.

(8)最大保存特征帧数,如果超过该帧数,将进行滚动保存.

Then we will open it laterdeepsort文件夹,You can see these things:

在这里插入图片描述 里面还是有sort算法的.

ckpt.t7:This is the weights file for a feature extraction network,This weight file will be generated after the feature extraction network is trained,It is convenient to extract features in the target frame during target tracking,Avoid while target trackingID交换.

evaluate.py:Calculate feature extraction model accuracy.

feature_extractor.py:提取对应boundingbox中的特征, Get a fixed-dimensional feature,作为该bounding box的代表,供计算相似度时使用.

model.py:Feature extraction network model,The model is used to extract training features to extract network weights. train.py:Train the feature extraction networkpython文件

test.py:Test the performance of the trained feature extraction network

then in additionsortThe algorithm corresponds to this thing 在这里插入图片描述 detection.py:Save a detection box detected by the target,As well as the confidence of the box and the acquired features;At the same time, the conversion methods of various formats of the frame are also provided.

iou_matching.py:Calculate between two boxesIOU.

kalman_filter.py:Relevant code for Kalman filter,It mainly uses Kalman filtering to predict the trajectory information of the detection frame.

linear_assignment.py:The Hungarian algorithm is used to match the predicted trajectory box and the detection box for the best matching effect.

nn_matching.py:By calculating the Euclidean distance、Cosine distance equidistant to calculate the nearest collar distance.

preprocessing.py:Non-maximum suppression code,Use the non-maximum suppression algorithm to output the optimal detection frame.

track.py:The main storage is track information,This includes the position and velocity information of the track box,track boxID和状态,There are three states,One is deterministic、不确定态、Delete state three states.

tracker.py:All track information is saved,Responsible for initializing the first frame,卡尔曼滤波的预测和更新,负责级联匹配,IOU匹配.

So go back to our root directory: 在这里插入图片描述

deep_sort/deep_sort/deep_sort.py:deepsortthe overall package,实现一个deepsortAn overall effect of tracking.

deep_sort/utils:Mainly there are some various tools herepython代码,For example the frame tool,Log saving tools and more.

fuck.py:针对读取的视频进行目标追踪

objdetector.py:封装的一个目标检测器,对视频中的物体进行检测

objtracker.py:封装了一个目标追踪器,对检测的物体进行追踪

最后来看看效果演示 请添加图片描述

copyright notice
author[the_way_inf],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/218/202208061751323052.html

Random recommended