• Stars
    star
    584
  • Rank 76,554 (Top 2 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

最新版本yolov5+deepsort目标检测和追踪,能够显示目标类别,支持5.0版本可训练自己数据集

本文禁止转载!

本文地址:https://blog.csdn.net/weixin_44936889/article/details/112002152

项目简介:

使用YOLOv5+Deepsort实现车辆行人追踪和计数,代码封装成一个Detector类,更容易嵌入到自己的项目中。

代码地址(欢迎star):

https://github.com/Sharpiless/yolov5-deepsort/

最终效果: 在这里插入图片描述

YOLOv5检测器:

class Detector(baseDet):

    def __init__(self):
        super(Detector, self).__init__()
        self.init_model()
        self.build_config()

    def init_model(self):

        self.weights = 'weights/yolov5m.pt'
        self.device = '0' if torch.cuda.is_available() else 'cpu'
        self.device = select_device(self.device)
        model = attempt_load(self.weights, map_location=self.device)
        model.to(self.device).eval()
        model.half()
        # torch.save(model, 'test.pt')
        self.m = model
        self.names = model.module.names if hasattr(
            model, 'module') else model.names

    def preprocess(self, img):

        img0 = img.copy()
        img = letterbox(img, new_shape=self.img_size)[0]
        img = img[:, :, ::-1].transpose(2, 0, 1)
        img = np.ascontiguousarray(img)
        img = torch.from_numpy(img).to(self.device)
        img = img.half()  # 半精度
        img /= 255.0  # 图像归一化
        if img.ndimension() == 3:
            img = img.unsqueeze(0)

        return img0, img

    def detect(self, im):

        im0, img = self.preprocess(im)

        pred = self.m(img, augment=False)[0]
        pred = pred.float()
        pred = non_max_suppression(pred, self.threshold, 0.4)

        pred_boxes = []
        for det in pred:

            if det is not None and len(det):
                det[:, :4] = scale_coords(
                    img.shape[2:], det[:, :4], im0.shape).round()

                for *x, conf, cls_id in det:
                    lbl = self.names[int(cls_id)]
                    if not lbl in ['person', 'car', 'truck']:
                        continue
                    x1, y1 = int(x[0]), int(x[1])
                    x2, y2 = int(x[2]), int(x[3])
                    pred_boxes.append(
                        (x1, y1, x2, y2, lbl, conf))

        return im, pred_boxes

调用 self.detect 方法返回图像和预测结果

DeepSort追踪器:

deepsort = DeepSort(cfg.DEEPSORT.REID_CKPT,
                    max_dist=cfg.DEEPSORT.MAX_DIST, min_confidence=cfg.DEEPSORT.MIN_CONFIDENCE,
                    nms_max_overlap=cfg.DEEPSORT.NMS_MAX_OVERLAP, max_iou_distance=cfg.DEEPSORT.MAX_IOU_DISTANCE,
                    max_age=cfg.DEEPSORT.MAX_AGE, n_init=cfg.DEEPSORT.N_INIT, nn_budget=cfg.DEEPSORT.NN_BUDGET,
                    use_cuda=True)

调用 self.update 方法更新追踪结果

运行demo:

python demo.py

训练自己的模型:

参考我的另一篇博客:

【小白CV】手把手教你用YOLOv5训练自己的数据集(从Windows环境配置到模型部署)

训练好后放到 weights 文件夹下

调用接口:

创建检测器:

from AIDetector_pytorch import Detector

det = Detector()

调用检测接口:

result = det.feedCap(im)

其中 im 为 BGR 图像

返回的 result 是字典,result['frame'] 返回可视化后的图像

联系作者:

B站:https://space.bilibili.com/470550823

CSDN:https://blog.csdn.net/weixin_44936889

AI Studio:https://aistudio.baidu.com/aistudio/personalcenter/thirdview/67156

Github:https://github.com/Sharpiless

遵循 GNU General Public License v3.0 协议,标明目标检测部分来源:https://github.com/ultralytics/yolov5/

More Repositories

1

Yolov5-deepsort-inference

Yolov5 deepsort inference,使用YOLOv5+Deepsort实现车辆行人追踪和计数,代码封装成一个Detector类,更容易嵌入到自己的项目中
Python
910
star
2

Yolov5-distillation-train-inference

Yolov5 distillation training | Yolov5知识蒸馏训练,支持训练自己的数据
Python
170
star
3

yolov5-distillation-5.0

yolov5 5.0 version distillation || yolov5 5.0版本知识蒸馏,yolov5l >> yolov5s
Jupyter Notebook
130
star
4

yolox-deepsort

基于YoloX目标检测+DeepSort算法实现多目标追踪Baseline
Python
126
star
5

yolov3-vehicle-detection-paddle

vehicle-detection based on yolov3(基于paddle的YOLOv3车辆检测和类型识别)
Python
113
star
6

Easy-AnimeGAN

From https://github.com/TachibanaYoshino/AnimeGAN, easier for a demo
Python
100
star
7

PaddleX-Flask-VUE-demo

基于PaddleX+Flask开发后端,基于VUE开发前端应用,做一个AI医疗的WEB应用
Vue
99
star
8

Yolov5-Flask-VUE

基于Flask开发后端、VUE开发前端框架,在WEB端部署YOLOv5目标检测模型
Python
78
star
9

play-daxigua-using-Reinforcement-Learning

用强化学习DQN算法,训练AI模型来玩合成大西瓜游戏,提供Keras版本和PARL(paddle)版本
Python
76
star
10

yolov5-knowledge-distillation

yolov5目标检测模型的知识蒸馏(基于响应的蒸馏)
Python
62
star
11

PaddleDetection-Pedestrians-Detection-and-Tracking

中软杯baseline-基于百度飞桨的单/多镜头行人追踪,使用百度飞桨PaddleDetection套件的PP-YOLO+Sort算法开发
Python
44
star
12

PaddleDetection-Yolov5

基于Paddlepaddle复现yolov5,支持PaddleDetection接口
Python
36
star
13

opencv-pyqt-makeup-software

基于opencv+pyqt5开发的美颜化妆软件,功能包括:图像锐化、亮睛、红唇、瘦脸、美肤等
Python
34
star
14

gobang-object-detection-dataset

北理BIT人工智能大作业,写脚本收集了黑/白棋子检测数据集并提供YOLOv3训练和推理代码
Jupyter Notebook
32
star
15

Face-recognition-for-classroom-sign-in

基于FaceNet的人脸检测+识别的课堂学生签到系统
Python
29
star
16

Pix2seq-mmdetection

Unofficial implement of "Pix2seq: A Language Modeling Framework for Object Detection" on mmdetection
Python
28
star
17

BITCS-final-exam-learning-materials

北理工计算机大一到大四各学期CS期末考试复习资料/历年考题汇总,欢迎PR
C
26
star
18

FCN-DenseNet

FCN implement with densenet for VOC dataset
Python
25
star
19

Paddle-face-detection-and-expression-recognition

基于Paddle框架的TinyYOLO人脸检测和ResNet表情识别
Jupyter Notebook
19
star
20

Point-Transformers-with-Quantization

基于Point Transformers复现点云分割任务,并使用HAQ算法进行自动量化压缩,几乎不影响精度
Python
18
star
21

paddleocr-enterprise-entity-recognition

【中软杯国二开源】基于PaddleOCR和深度学习的企业实体识别
Jupyter Notebook
17
star
22

Easy-Pelee-Detection

A Pelee demo easier for demo(直接跑检测的那种)
Python
17
star
23

Versailles-text-generation-with-paddlepaddle

使用Paddlehub实现最近大火的凡尔赛文案自动生成
Jupyter Notebook
16
star
24

Point-Transformer-Pytorch

基于Pytorch复现Point-Transformer,用于ShapeNet数据集点云分割
Python
16
star
25

yolov5_export_quant_model

yolov5模型训练后量化代码
Python
14
star
26

paddlex-vehicle-detection-with-YOLOv3

(车辆检测和车道分割)vehicle detection and lane segmentation based on YOLOv3 with paddlex
Jupyter Notebook
14
star
27

HAQ-for-Mobilenetv3-Quantization

用于 MobileNetV3 在自定义数据集上的量化,模型压缩90%而精度几乎不受影响,论文:HAQ: Hardware-Aware Automated Quantization with Mixed Precision
Python
13
star
28

Awesome-datafree-KD

2019~2021年间Zero-shot/Data-free知识蒸馏的论文合集
11
star
29

PARL-DQN-daxigua

用parl框架的DQN强化学习算法玩“合成大西瓜”
Python
11
star
30

Tianchi-PANDA-rank13

PANDA大场景多对象检测跟踪(初赛检测)开源代码,初赛排名13
Python
11
star
31

play-Pacman-with-gesture-recognition-by-resnet18

手把手教你用PaddleX训练手势识别模型,并将该模型用于吃豆豆游戏
Python
10
star
32

Yolov3-plate-detection

Chinese plate detection(基于YOLOv3的中文车牌检测)
Python
10
star
33

Social-safety-distance-detection-with-paddlepaddle

基于Paddlepaddle的社交行人安全距离检测
Jupyter Notebook
9
star
34

yolov3-vehicle-plate-recognition-

基于Yolov3的中文车牌检测和识别
Python
9
star
35

play-daxigua-using-PaddleX

使用PaddleX在浏览器自动玩合成大西瓜
Python
9
star
36

pacman-with-paddlepaddle-gesture-control

pacman with paddlepaddle gesture control,手势识别用于吃豆人小游戏
Python
8
star
37

PyQt5-based-Remote-Medical-System-v1.0

基于PyQt5开发,使用多线程和Socket通信,北理18级小学期大作业,远程医疗云监控系统
Python
7
star
38

pp-yolo-vehcile-detection-and-distance-estimation-for-self-driving

a
Python
7
star
39

lane-detection-for-huawei-competition

2021第三届华为云人工智能大赛 · 无人车挑战杯——车道线检测模块
Python
7
star
40

Play-Tetris-Using-hand-gesture-recognition

使用手势识别算法玩俄罗斯方块
Python
7
star
41

ZSKD-pytorch

Pytorch implement of Zero-shot Knowledge Distillation in Deep Neural Networks
Python
5
star
42

Star-face-recognition

基于FaceNet的明星人脸识别
Python
5
star
43

Yolov3-MobileNet-Distillation

在Yolov3-MobileNet上进行模型蒸馏训练
Jupyter Notebook
5
star
44

SSD-tensorflow

SSD on tensorflow
Python
5
star
45

FCN-tensorflow

Semantic Segmentation by FCN
Python
5
star
46

MPI-Flow

Official Code of "[ICCV 2023] MPI-Flow: Learning Realistic Optical Flow with Multiplane Images"
4
star
47

BIT-AI-final-exam-papers

北京理工大学人工智能基础考试卷(目前两套)
4
star
48

offline-image-argument

离线数据增强,自动生成对应的标注文件
Python
4
star
49

Hand-gesture-recognition-for-game

手势识别玩转打飞机小游戏,基于MobileNetV3_Small和pygame
Python
4
star
50

Paddlepaddle-CenterNet

基于Paddlepaddle2.0动态图版本复现CenterNet
Python
3
star
51

Crawler-for-pokemon

Python
3
star
52

Gold-Miner

汇编大作业,黄金矿工
Assembly
3
star
53

Temporal-Difference

Temporal Difference by opencv
Python
3
star
54

RESNET-tensorflow

resnet on tensorflow
Python
3
star
55

Driver-status-recognition-with-paddlex

(驾驶员状态识别)Driver status recognition with paddlex based on MobileNetv3
Jupyter Notebook
3
star
56

HeartRate

rppg based hr estimator
Python
2
star
57

SSD-video-detector-tensorflow

SSD-video-detector-tensorflow
Python
2
star
58

Sharpiless

2
star
59

DenseNet-tensorflow

DenseNet tensorflow
Python
2
star
60

paddlex-driver-state-recognition

paddlex-baseddriver face detection and state recognition
Java
2
star
61

Face-and-key-points-detector

Python
1
star
62

VGG-tensorflow

Python
1
star
63

Train-RAFT-from-single-view-images

Official Code (new released) of "[ICCV 2023] MPI-Flow: Learning Realistic Optical Flow with Multiplane Images"
Python
1
star
64

BIT-Machine-Learning-Fundamentals

北理工-2018级计科-机器学习基础-小作业和大作业
1
star
65

Animation-splicing-picture

Animation splicing picture
Python
1
star
66

Lane-Detector-for-Huawei-Driverless-Car-Race

第二届华为云人工智能大赛——车道线检测算法
Python
1
star
67

faster-rcnn-mobilenetv2

faster-rcnn-mobilenetv2 using tensorflow
1
star
68

faster-rcnn-mobilenetv2-tf

faster-rcnn-mobilenetv2-tf
1
star
69

faster-rcnn-tf

faster-rcnn-tensorflow
Python
1
star
70

test

no
Python
1
star
71

Heart-rate-monitor

Heart rate monitoring
1
star
72

Crawler-for-LOL-skin

Crawler for LOL skin
Python
1
star
73

Zip-code-identification

Zip code identification using cnn
Python
1
star
74

Anime-Mosaic-Puzzle

动漫人物拼图
Python
1
star
75

Flow-Anything

1
star