具体参考:(如果侵权,速删)
- https://zhuanlan.zhihu.com/p/354945895
- https://blog.csdn.net/qq_44703886/article/details/121327643
3.https://blog.csdn.net/weixin_50008473/article/details/122347582
4.https://zhuanlan.zhihu.com/p/50387521
5.https://blog.csdn.net/fengdu78/article/details/119431155
6.https://blog.csdn.net/didiaopao/article/details/120274519
github:1.https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch
2.https://github.com/layumi/Person_reID_baseline_pytorch
环境:
Nvidia RTX 3060
Ubuntu 16.04
CUDA 11.1
cuDNN 8.2.0
torch 1.10.1+cu111
torchvision 0.11.2+cu111
一、搭建YOLOv5-DeepSORT虚拟环境
1.使用conda创建 YOLOv5-DeepSORT 需要的环境
conda create -n yolov5_deepsort python=3.8 //yolov5_deepsort是虚拟环境的名字
source activate yolov5_deepsort
2.下载YOLOv5-DeepSORT工程
YOLOv5-DeepSORT版本需要和YOLOv5版本对应,对应关系参考另一篇文章:https://www.jianshu.com/p/bfec81af1cf9 (亲测YOLOv5 v5.0 + DeepSORT v2.0 可运行)
(1)YOLOv5-DeepSORT官网地址:https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch
//DeepSORT 官网版本
git clone https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch
(2)YOLOv5-DeepSORT版本有很多,也可以点击 master - tag可以下载不同的版本
使用zip解压命令:unzip Yolov5_DeepSort_Pytorch-2.0(以v2.0为例)
3.安装依赖
cd Yolov5_DeepSort_Pytorch-2.0
注意:requirements.txt依赖项的Python 3.8 或更高版本,包括torch>=1.7.0,torchvision>=0.8.1
(1)可以使用pip命令安装
pip install -r requirements.txt
(2)pytorch及各种import可自行安装,注意pytorch和cuda版本需对应,官网地址:https://pytorch.org/get-started/previous-versions/ 对应关系如下:
本文选择使用官网命令进行安装,torch 1.10.1+cu111,torchvision 0.11.2+cu111
pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
import:
需要下载的包
(1)出现问题:ModuleNotFoundError: No module named 'cv2'
pip install opencv-python
(2)出现问题:ModuleNotFoundError: No module named 'pandas'
pip install pandas
(3)出现问题:ModuleNotFoundError: No module named 'requests'
pip install requests
(4)出现问题:ModuleNotFoundError: No module named 'yaml'
pip install pyyaml
(5)出现问题:ModuleNotFoundError: No module named 'tqdm'
pip install tqdm
(6)出现问题:ModuleNotFoundError: No module named 'matplotlib'
pip install matplotlib
(7)出现问题:ModuleNotFoundError: No module named 'seaborn'
pip install seaborn
二、训练自己的数据
1.需要准备的如下文件
(1)YOLOv5权重文件,放在~/code/Yolov5_DeepSort_Pytorch-3.0/yolov5/runs/train/exp4/weights下的best.pt
(2)重识别/分类模型,放在~/code/Yolov5_DeepSort_Pytorch-3.0/deep_sort_pytorch/deep_sort/deep/checkpoint下的ckpt.t7
(3)待追踪的视频,放在~/code/Yolov5_DeepSort_Pytorch-3.0下的800-1.avi
2.执行命令:
cd ~/code/Yolov5_DeepSort_Pytorch-3.0
python track.py --yolo_weights yolov5/weights/best.pt --source 800-1.mp4 --deep_sort_weights deep_sort_pytorch/deep_sort/deep/checkpoint/ckpt.t7 --device 0 --save-vid --save-txt
YOLOv5 v2.0版本出现问题除了下载一堆包以外,遇到两个问题
问题1:RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
解决方法参考:https://blog.csdn.net/weixin_44612221/article/details/115359866
问题2:AttributeError: Can't get attribute 'SPPF' on
解决方法参考:https://www.bilibili.com/read/cv14568709