-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shriram
committed
Mar 1, 2022
0 parents
commit 1888663
Showing
296 changed files
with
40,322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[submodule "yolov5"] | ||
path = yolov5 | ||
url = https://github.com/ultralytics/yolov5.git | ||
|
||
[submodule "deep_sort/deep/reid"] | ||
path = deep_sort/deep/reid | ||
url = https://github.com/KaiyangZhou/deep-person-reid |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/bin/bash | ||
|
||
set +e | ||
alias wget='curl -O' | ||
|
||
# start from clean slate | ||
# for i in data.zip MOT16.zip | ||
# do | ||
# zip -T $i | ||
# if [ $? -eq 0 ] | ||
# then | ||
# echo 'zip is ok' | ||
|
||
# else | ||
# echo 'zip corrupted, deleting' | ||
# rm -rf $i | ||
# fi | ||
# done | ||
|
||
|
||
# create output folder if it doesn't exist | ||
if [ ! -d D:/Curveball/Yolov5_DeepSort_Pytorch/inference/output ] | ||
then | ||
mkdir -p D:/Curveball/Yolov5_DeepSort_Pytorch/inference/output | ||
echo 'inference output folder created' | ||
fi | ||
|
||
|
||
|
||
# clone evaluation repo if it does not exist | ||
# if [ ! -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval ] | ||
# then | ||
# echo 'Cloning official MOT16 evaluation repo' | ||
# git clone https://github.com/JonathonLuiten/TrackEval D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval | ||
# # download quick start data folder if it does not exist | ||
# if [ ! -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data ] | ||
# then | ||
# # download data | ||
# wget -nc https://omnomnom.vision.rwth-aachen.de/data/TrackEval/data.zip -O D:/Curveball/Yolov5_DeepSort_Pytorch/data.zip | ||
# # unzip | ||
# unzip -q D:/Curveball/Yolov5_DeepSort_Pytorch/data.zip -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/ | ||
# # delete zip | ||
# #rm data.zip | ||
# fi | ||
# fi | ||
|
||
|
||
# create MOT16 folder if it doesn't exist | ||
# if [ ! -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16 ] | ||
# then | ||
# mkdir -p D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16 | ||
# fi | ||
|
||
|
||
# if MOT16 data not unziped, then download, unzip and lastly remove zip MOT16 data | ||
# if [[ ! -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16/train ]] && [[ ! -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16/test ]] | ||
# then | ||
# # download data | ||
# wget -nc https://motchallenge.net/data/MOT16.zip -O D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16.zip | ||
# # unzip | ||
# unzip -q MOT16.zip -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16/ | ||
# # delete zip | ||
# #rm MOT16.zip | ||
# fi | ||
|
||
|
||
# create folder to place tracking results for this method | ||
mkdir -p D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/trackers/mot_challenge/MOT16-train/ch_yolov5m_deep_sort/data/ | ||
|
||
# inference on 4 MOT16 video sequences at the same time | ||
# suits a 4GB GRAM GPU, feel free to increase if you have more memory | ||
N=2 | ||
|
||
# generate tracking results for each sequence | ||
for i in MOT16-02 MOT16-04 MOT16-05 MOT16-09 MOT16-10 MOT16-11 MOT16-13 | ||
do | ||
( | ||
# change name to inference source so that each thread write to its own .txt file | ||
if [ ! -d D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16/train/$i/$i ] | ||
then | ||
mv D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16/train/$i/img1/ D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16/train/$i/$i | ||
fi | ||
# run inference on sequence frames | ||
python track.py --source D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/MOT16/train/$i/$i --save-txt --evaluate --yolo_model yolov5/weights/crowdhuman_yolov5m.pt --classes 0 --exist-ok | ||
# move generated results to evaluation repo | ||
) & | ||
# https://unix.stackexchange.com/questions/103920/parallelize-a-bash-for-loop | ||
# allow to execute up to $N jobs in parallel | ||
if [[ $(jobs -r -p | wc -l) -ge $N ]] | ||
then | ||
# now there are $N jobs already running, so wait here for any job | ||
# to be finished so there is a place to start next one. | ||
wait -n | ||
fi | ||
done | ||
|
||
# no more jobs to be started but wait for pending jobs | ||
# (all need to be finished) | ||
wait | ||
echo "Inference on all MOT16 sequences DONE" | ||
|
||
echo "Moving data from experiment folder to MOT16" | ||
mv D:/Curveball/Yolov5_DeepSort_Pytorch/runs/track/exp/* \ | ||
D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/data/trackers/mot_challenge/MOT16-train/ch_yolov5m_deep_sort/data/ | ||
|
||
# run the evaluation | ||
python D:/Curveball/Yolov5_DeepSort_Pytorch/MOT16_eval/TrackEval/scripts/run_mot_challenge.py --BENCHMARK MOT16 \ | ||
--TRACKERS_TO_EVAL ch_yolov5m_deep_sort --SPLIT_TO_EVAL train --METRICS CLEAR Identity \ | ||
--USE_PARALLEL False --NUM_PARALLEL_CORES 4 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Pedestrian Speed Estimation using yolov5, deepsort and homography matrix | ||
|
||
## Demo gif | ||
|
||
<img src="MOT16_eval/demo.gif" width="600"/> | ||
|
||
## Before you run the tracker | ||
|
||
1. Clone the repository | ||
|
||
2. Install dependencies | ||
|
||
`pip install -r requirements.txt` | ||
|
||
## Download weights | ||
|
||
Download [weights](https://drive.google.com/file/d/1gglIwqxaH2iTvy6lZlXuAcMpd_U0GCUb/view?usp=sharing) and place it in yolov5/weights folder | ||
|
||
## Quick run | ||
Add a video to data/videos folder and run the following command. | ||
|
||
```bash | ||
python track.py --source data/videos/test.mp4 --yolo_model yolov5/weights/crowdhuman_yolov5m.pt --classes 0 --show-vid --save-vid | ||
``` | ||
|
||
Results are saved to folder `track/expN` | ||
|
||
## Tracking sources | ||
|
||
Tracking can be run on most video formats | ||
|
||
```bash | ||
$ python track.py --source 0 # webcam | ||
img.jpg # image | ||
vid.mp4 # video | ||
path/ # directory | ||
path/*.jpg # glob | ||
'https://youtu.be/Zgi9g1ksQHc' # YouTube | ||
'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream | ||
``` | ||
|
||
### DeepSort | ||
|
||
Choose a ReID model based on your needs from this ReID [model zoo](https://kaiyangzhou.github.io/deep-person-reid/MODEL_ZOO) | ||
|
||
```bash | ||
|
||
|
||
$ python track.py --source 0 --deep_sort_model osnet_x1_0 | ||
nasnsetmobile | ||
resnext101_32x8d | ||
... | ||
``` | ||
## Reference | ||
|
||
```latex | ||
@misc{yolov5deepsort2020, | ||
title={Real-time multi-object tracker using YOLOv5 and deep sort}, | ||
author={Mikel Broström}, | ||
howpublished = {\url{https://github.com/mikel-brostrom/Yolov5_DeepSort_Pytorch}}, | ||
year={2020} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Folders | ||
__pycache__/ | ||
build/ | ||
*.egg-info | ||
|
||
|
||
# Files | ||
*.weights | ||
*.t7 | ||
*.mp4 | ||
*.avi | ||
*.so | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Ziqiang | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Deep Sort with PyTorch | ||
|
||
![](demo/demo.gif) | ||
|
||
## Update(1-1-2020) | ||
Changes | ||
- fix bugs | ||
- refactor code | ||
- accerate detection by adding nms on gpu | ||
|
||
## Latest Update(07-22) | ||
Changes | ||
- bug fix (Thanks @JieChen91 and @yingsen1 for bug reporting). | ||
- using batch for feature extracting for each frame, which lead to a small speed up. | ||
- code improvement. | ||
|
||
Futher improvement direction | ||
- Train detector on specific dataset rather than the official one. | ||
- Retrain REID model on pedestrain dataset for better performance. | ||
- Replace YOLOv3 detector with advanced ones. | ||
|
||
**Any contributions to this repository is welcome!** | ||
|
||
|
||
## Introduction | ||
This is an implement of MOT tracking algorithm deep sort. Deep sort is basicly the same with sort but added a CNN model to extract features in image of human part bounded by a detector. This CNN model is indeed a RE-ID model and the detector used in [PAPER](https://arxiv.org/abs/1703.07402) is FasterRCNN , and the original source code is [HERE](https://github.com/nwojke/deep_sort). | ||
However in original code, the CNN model is implemented with tensorflow, which I'm not familier with. SO I re-implemented the CNN feature extraction model with PyTorch, and changed the CNN model a little bit. Also, I use **YOLOv3** to generate bboxes instead of FasterRCNN. | ||
|
||
## Dependencies | ||
- python 3 (python2 not sure) | ||
- numpy | ||
- scipy | ||
- opencv-python | ||
- sklearn | ||
- torch >= 0.4 | ||
- torchvision >= 0.1 | ||
- pillow | ||
- vizer | ||
- edict | ||
|
||
## Quick Start | ||
0. Check all dependencies installed | ||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
for user in china, you can specify pypi source to accelerate install like: | ||
```bash | ||
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple | ||
``` | ||
|
||
1. Clone this repository | ||
``` | ||
git clone git@github.com:ZQPei/deep_sort_pytorch.git | ||
``` | ||
|
||
2. Download YOLOv3 parameters | ||
``` | ||
cd detector/YOLOv3/weight/ | ||
wget https://pjreddie.com/media/files/yolov3.weights | ||
wget https://pjreddie.com/media/files/yolov3-tiny.weights | ||
cd ../../../ | ||
``` | ||
|
||
3. Download deepsort parameters ckpt.t7 | ||
``` | ||
cd deep_sort/deep/checkpoint | ||
# download ckpt.t7 from | ||
https://drive.google.com/drive/folders/1xhG0kRH1EX5B9_Iz8gQJb7UNnn_riXi6 to this folder | ||
cd ../../../ | ||
``` | ||
|
||
4. Compile nms module | ||
```bash | ||
cd detector/YOLOv3/nms | ||
sh build.sh | ||
cd ../../.. | ||
``` | ||
|
||
Notice: | ||
If compiling failed, the simplist way is to **Upgrade your pytorch >= 1.1 and torchvision >= 0.3" and you can avoid the troublesome compiling problems which are most likely caused by either `gcc version too low` or `libraries missing`. | ||
|
||
5. Run demo | ||
``` | ||
usage: python yolov3_deepsort.py VIDEO_PATH | ||
[--help] | ||
[--frame_interval FRAME_INTERVAL] | ||
[--config_detection CONFIG_DETECTION] | ||
[--config_deepsort CONFIG_DEEPSORT] | ||
[--display] | ||
[--display_width DISPLAY_WIDTH] | ||
[--display_height DISPLAY_HEIGHT] | ||
[--save_path SAVE_PATH] | ||
[--cpu] | ||
# yolov3 + deepsort | ||
python yolov3_deepsort.py [VIDEO_PATH] | ||
# yolov3_tiny + deepsort | ||
python yolov3_deepsort.py [VIDEO_PATH] --config_detection ./configs/yolov3_tiny.yaml | ||
# yolov3 + deepsort on webcam | ||
python3 yolov3_deepsort.py /dev/video0 --camera 0 | ||
# yolov3_tiny + deepsort on webcam | ||
python3 yolov3_deepsort.py /dev/video0 --config_detection ./configs/yolov3_tiny.yaml --camera 0 | ||
``` | ||
Use `--display` to enable display. | ||
Results will be saved to `./output/results.avi` and `./output/results.txt`. | ||
|
||
All files above can also be accessed from BaiduDisk! | ||
linker:[BaiduDisk](https://pan.baidu.com/s/1YJ1iPpdFTlUyLFoonYvozg) | ||
passwd:fbuw | ||
|
||
## Training the RE-ID model | ||
The original model used in paper is in original_model.py, and its parameter here [original_ckpt.t7](https://drive.google.com/drive/folders/1xhG0kRH1EX5B9_Iz8gQJb7UNnn_riXi6). | ||
|
||
To train the model, first you need download [Market1501](http://www.liangzheng.com.cn/Project/project_reid.html) dataset or [Mars](http://www.liangzheng.com.cn/Project/project_mars.html) dataset. | ||
|
||
Then you can try [train.py](deep_sort/deep/train.py) to train your own parameter and evaluate it using [test.py](deep_sort/deep/test.py) and [evaluate.py](deep_sort/deep/evalute.py). | ||
![train.jpg](deep_sort/deep/train.jpg) | ||
|
||
## Demo videos and images | ||
[demo.avi](https://drive.google.com/drive/folders/1xhG0kRH1EX5B9_Iz8gQJb7UNnn_riXi6) | ||
[demo2.avi](https://drive.google.com/drive/folders/1xhG0kRH1EX5B9_Iz8gQJb7UNnn_riXi6) | ||
|
||
![1.jpg](demo/1.jpg) | ||
![2.jpg](demo/2.jpg) | ||
|
||
|
||
## References | ||
- paper: [Simple Online and Realtime Tracking with a Deep Association Metric](https://arxiv.org/abs/1703.07402) | ||
|
||
- code: [nwojke/deep_sort](https://github.com/nwojke/deep_sort) | ||
|
||
- paper: [YOLOv3](https://pjreddie.com/media/files/papers/YOLOv3.pdf) | ||
|
||
- code: [Joseph Redmon/yolov3](https://pjreddie.com/darknet/yolo/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .deep_sort import DeepSort | ||
|
||
|
||
__all__ = ['DeepSort', 'build_tracker'] | ||
|
||
|
||
def build_tracker(cfg, use_cuda): | ||
return 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=use_cuda) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
DEEPSORT: | ||
MODEL_TYPE: "osnet_x1_0" | ||
MAX_DIST: 0.2 # The matching threshold. Samples with larger distance are considered an invalid match | ||
MAX_IOU_DISTANCE: 0.7 # Gating threshold. Associations with cost larger than this value are disregarded. | ||
MAX_AGE: 30 # Maximum number of missed misses before a track is deleted | ||
N_INIT: 3 # Number of frames that a track remains in initialization phase | ||
NN_BUDGET: 100 # Maximum size of the appearance descriptors gallery | ||
|
Empty file.
Empty file.
Oops, something went wrong.