赞
踩
项目源码
pytorch yolo5+Deepsort实现目标检测和跟踪
YoloV5 + deepsort + Fast-ReID 完整行人重识别系统(三)
yolov5-deepsort-pedestrian-counting
Yolov5-Deepsort-Fastreid
Deepsort是实现目标跟踪的算法,从sort(simple online and realtime tracking)演变而来。其使用卡尔慢滤波器预测所检测对象的运动轨迹,匈牙利算法将它们与新检测的目标匹配。Deepsort易于使用,且速度快,成为AI目标检测跟踪的热门算法。
yolov5可检测多种类型的目标,而Deepsort目标跟踪只能跟踪一种类型目标,例如person、car。所以,跟踪需要把yolov5的目标检测类型数量限制成单个类型检测。coco数据集定义:person=0,car=2。
# 行人跟踪
python track.py --classes 0 --source demo_person.mp4
# 小汽车跟踪
python track.py --classes 2 --source demo_car.mp4
yolov5提供不同检测精度的权重文件,yolov5x.pt比yolov5s.pt精度高。应用跟踪时,当两个目标重叠后再分离,yolov5s.pt会出现标注数改变。比如,目标10和目标20发生重叠分离,目标10变成了目标15,而目标20不变(目标20遮挡目标10)。此种情况,用yolov5x.pt会好很多,维持目标10不变。
yolov5限定单个类型,不需要重新训练。faster rcnn、ResNet限定单个类型,单需要重新训练。
yolov5的速度明显优于FastRCNN,且消耗GPU资源少。用FastRCNN,还没用到Deepsort,只看逐帧检测,速度比yolov5+Deepsort逐帧目标检测还要慢,且GPU使用率达到95%。
yolov5的训练速度比Faster RCNN、ResNet50、FPN快。
Environment
Operating System + Version: Ubuntu + 16.04
GPU Type: GeForce GTX1650,4GB
Nvidia Driver Version: 470.63.01
CUDA Version: 10.2.300
CUDNN Version: 7.6.5
Python Version (if applicable): 3.6.14
virtualenv:20.13.0
gcc:7.5.0
g++:7.5.0
absl-py==1.0.0
cached-property==1.5.2
cachetools==4.2.4
certifi==2021.10.8
charset-normalizer==2.0.10
cycler==0.11.0
Cython==0.29.26
dataclasses==0.8
distlib==0.3.4
easydict==1.9
filelock==3.4.1
flake8==4.0.1
future==0.18.2
gdown==3.10.1
google-auth==2.3.3
google-auth-oauthlib==0.4.6
grpcio==1.43.0
h5py==3.1.0
idna==3.3
imageio==2.13.5
importlib-metadata==4.2.0
importlib-resources==5.4.0
isort==4.3.21
kiwisolver==1.3.1
Markdown==3.3.5
matplotlib==3.3.4
mccabe==0.6.1
numpy==1.19.5
oauthlib==3.1.1
opencv-python==4.5.5.62
pandas==1.1.5
Pillow==8.4.0
platformdirs==2.4.0
protobuf==3.19.3
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.8.0
pyflakes==2.4.0
pyparsing==3.0.6
PySocks==1.7.1
python-dateutil==2.8.2
pytz==2021.3
PyYAML==6.0
requests==2.27.1
requests-oauthlib==1.3.0
rsa==4.8
scipy==1.5.4
seaborn==0.11.2
six==1.16.0
tb-nightly==2.8.0a20220117
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
torch==1.9.0+cu102
torchvision=0.10.0+cu102
tqdm==4.62.3
typing_extensions==4.0.1
urllib3==1.26.8
virtualenv==20.13.0
Werkzeug==2.0.2
yacs==0.1.8
yapf==0.32.0
zipp==3.6.0
git clone https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch.git
.
├── deep_sort
│ ├── configs
│ ├── deep
│ ├── deep_sort.py
│ ├── __init__.py
│ ├── LICENSE
│ ├── __pycache__
│ ├── README.md
│ ├── sort
│ └── utils
├── inference # infer 推理的结果
│ └── output
├── LICENSE
├── MOT16_eval
│ ├── eval.sh
│ ├── track_all.gif
│ └── track_pedestrians.gif
├── README.md
├── requirementes-gpu.txt
├── requirements.txt
├── runs
│ └── track
├── track.py
├── venv # virtualenv 创建的虚拟环境
│ ├── bin
│ ├── lib
│ └── pyvenv.cfg
├── yolov5 # clone yolov5 to this path
│ ├── CONTRIBUTING.md
│ ├── data
│ ├── detect.py
│ ├── Dockerfile
│ ├── export.py
│ ├── hubconf.py
│ ├── LICENSE
│ ├── models
│ ├── README.md
│ ├── requirements.txt
│ ├── setup.cfg
│ ├── train.py
│ ├── tutorial.ipynb
│ ├── utils
│ ├── val.py
│ └── weights
下载到 Yolov5_DeepSort_Pytorch
根目录下,删除之前的yolov5文件夹。
git clone https://github.com/ultralytics/yolov5.git
deep-person-reid
改为
reid
# 进入项目路径
cd Yolov5_DeepSort_Pytorch
# 创建虚拟环境
virtualenv --system-site-packages -p /usr/bin/python venv
# 激活虚拟环境
source ./venv/bin/activate
# 安装依赖包
pip install -r requirements.txt
选择目标检测模型:yolov5;
选择DeepSort模型:ReID;
下载地址,并放入目录 Yolov5_DeepSort_Pytorchyolo5/weights
比如, yolov5s.pt
python track.py --source 0 --yolo_model yolov5/weights/yolov5n.pt --img 640
yolov5/weights/yolov5s.pt
yolov5/weights/yolov5m.pt
yolov5/weights/yolov5l.pt
yolov5/weights/yolov5x.pt --img 1280
...
下载地址,放入目录 Yolov5_DeepSort_Pytorch/deep_sort_pytorch/deep_sort/deep/checkpoint
比如,osnet_x1_0
python track.py --source 0 --deep_sort_model osnet_x1_0
nasnsetmobile
resnext101_32x8d
python track.py --source 0 --yolo_model yolov5/weights/yolov5n.pt --deep_sort_model osnet_x1_0 --img 640
(venv) yichao@yichao:~/MyDocuments/Yolov5_DeepSort_Pytorch$ python track.py --source 0 --yolo_model yolov5/weights/yolov5s.pt --deep_sort_model osnet_x1_0 --img 640
deep_sort/deep/reid/torchreid/metrics/rank.py:12: UserWarning: Cython evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython evaluation (very fast so highly recommended) is '
Successfully loaded imagenet pretrained weights from "/home/yichao/MyDocuments/Yolov5_DeepSort_Pytorch/deep_sort/deep/checkpoint/osnet_x1_0_imagenet.pth"
Selected model type: osnet_x1_0
YOLOv5 声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/312979
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。