[go: up one dir, main page]

Skip to content

Deepsort with yolo series. This project support the existing yolo detection model algorithm (YOLOV8, YOLOV7, YOLOV6, YOLOV5, YOLOV4Scaled, YOLOV4, YOLOv3', PPYOLOE, YOLOR, YOLOX ).

License

Notifications You must be signed in to change notification settings

xuarehere/yolo_series_deepsort_pytorch

Repository files navigation

Table of contents

Introduction

This is an implement of MOT tracking algorithm deep sort. Currently, the project supports models of the mainstream yolo series model. This project add the existing yolo detection model algorithm (YOLOv3, YOLOV4, YOLOV4Scaled, YOLOV5, YOLOV6, YOLOV7, YOLOV8, YOLOX, YOLOR, PPYOLOE). Therefore, it is sometimes called the following name:

  • YOLOv3-DeepSort
  • YOLOV4-DeepSort
  • YOLOV4Scaled-DeepSort
  • YOLOV5-DeepSort
  • YOLOV6-DeepSort
  • YOLOV7-DeepSort
  • YOLOV8-DeepSort
  • YOLOX-DeepSort
  • YOLOR-DeepSort
  • PPYOLOE-DeepSort

Also, this project is compatible with the original object detection model structure. Individual training and inference of the detection model can be performed.

Model

Object detection

  • MMDet
  • YOLOv3
  • YOLOV4
  • YOLOV4Scaled
  • YOLOV5
  • YOLOV6
  • YOLOV7
  • YOLOV8
  • YOLOX
  • YOLOR
  • PPYOLOE

ReID

  • deepsort-reid
  • fast-reid

Project structure

Expand
yolovx_deepsort_pytorch/
β”œβ”€β”€ 001.avi
β”œβ”€β”€ checkpoint
β”œβ”€β”€ configs
β”‚   β”œβ”€β”€ deep_sort.yaml
β”‚   β”œβ”€β”€ fastreid.yaml
β”‚   β”œβ”€β”€ mmdet.yaml
β”‚   β”œβ”€β”€ ppyoloe.yaml
β”‚   β”œβ”€β”€ yolor.yaml
β”‚   β”œβ”€β”€ yolov3_tiny.yaml
β”‚   β”œβ”€β”€ yolov3.yaml
β”‚   β”œβ”€β”€ yolov4Scaled.yaml
β”‚   β”œβ”€β”€ yolov4.yaml
β”‚   β”œβ”€β”€ yolov5.yaml
β”‚   β”œβ”€β”€ yolov6.yaml
β”‚   β”œβ”€β”€ yolov7.yaml
β”‚   └── yolox.yaml
β”œβ”€β”€ deep_sort
β”‚   β”œβ”€β”€ deep
β”‚   β”œβ”€β”€ deep_sort.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ __pycache__
β”‚   β”œβ”€β”€ README.md
β”‚   └── sort
β”œβ”€β”€ deepsort.py
β”œβ”€β”€ demo
β”‚   β”œβ”€β”€ 1.jpg
β”‚   β”œβ”€β”€ 2.jpg
β”‚   └── demo.gif
β”œβ”€β”€ detector
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ MMDet
β”‚   β”œβ”€β”€ PPYOLOE
β”‚   β”œβ”€β”€ __pycache__
β”‚   β”œβ”€β”€ YOLOR
β”‚   β”œβ”€β”€ YOLOv3
β”‚   β”œβ”€β”€ YOLOV4
β”‚   β”œβ”€β”€ YOLOV4Scaled
β”‚   β”œβ”€β”€ YOLOV5
β”‚   β”œβ”€β”€ YOLOV6
β”‚   β”œβ”€β”€ YOLOV7
β”‚   └── YOLOX
β”œβ”€β”€ LICENSE
β”œβ”€β”€ models
β”‚   β”œβ”€β”€ deep_sort_pytorch
β”‚   β”œβ”€β”€ ppyoloe
β”‚   β”œβ”€β”€ readme.md
β”‚   β”œβ”€β”€ yolor
β”‚   β”œβ”€β”€ yolov3
β”‚   β”œβ”€β”€ yolov4
β”‚   β”œβ”€β”€ yolov4-608
β”‚   β”œβ”€β”€ yolov4Scaled
β”‚   β”œβ”€β”€ yolov5
β”‚   β”œβ”€β”€ yolov6
β”‚   β”œβ”€β”€ yolov7
β”‚   └── yolox
β”œβ”€β”€ output
β”‚   β”œβ”€β”€ ppyoloe
β”‚   β”œβ”€β”€ README.MD
β”‚   β”œβ”€β”€ yolor
β”‚   β”œβ”€β”€ yolov3
β”‚   β”œβ”€β”€ yolov4
β”‚   β”œβ”€β”€ yolov4Scaled
β”‚   β”œβ”€β”€ yolov5
β”‚   β”œβ”€β”€ yolov6
β”‚   β”œβ”€β”€ yolov7
β”‚   └── yolox
β”œβ”€β”€ ped_det_server.py
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ results_analysis
β”‚   └── analysis.py
β”œβ”€β”€ scripts
β”‚   β”œβ”€β”€ yoloe.sh
β”‚   β”œβ”€β”€ yolor.sh
β”‚   β”œβ”€β”€ yolov3_deepsort.sh
β”‚   β”œβ”€β”€ yolov3_tiny_deepsort.sh
β”‚   β”œβ”€β”€ yolov4_deepsort.sh
β”‚   β”œβ”€β”€ yolov4Scaled_deepsort.sh
β”‚   β”œβ”€β”€ yolov5_deepsort.sh
β”‚   β”œβ”€β”€ yolov6_deepsort.sh
β”‚   β”œβ”€β”€ yolov7_deepsort.sh
β”‚   └── yolox_deepsort.sh
β”œβ”€β”€ thirdparty
β”‚   β”œβ”€β”€ fast-reid
β”‚   └── mmdetection
β”œβ”€β”€ train.jpg
β”œβ”€β”€ tutotial
β”‚   β”œβ”€β”€ Hungarian_Algorithm.ipynb
β”‚   β”œβ”€β”€ kalman_filter.ipynb
β”‚   └── kalman_filter.py
β”œβ”€β”€ utils
β”‚   β”œβ”€β”€ asserts.py
β”‚   β”œβ”€β”€ draw.py
β”‚   β”œβ”€β”€ evaluation.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ io.py
β”‚   β”œβ”€β”€ json_logger.py
β”‚   β”œβ”€β”€ log.py
β”‚   β”œβ”€β”€ parser.py
β”‚   β”œβ”€β”€ __pycache__
β”‚   └── tools.py
β”œβ”€β”€ webserver
β”‚   β”œβ”€β”€ config
β”‚   β”œβ”€β”€ images
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ readme.md
β”‚   β”œβ”€β”€ rtsp_threaded_tracker.py
β”‚   β”œβ”€β”€ rtsp_webserver.py
β”‚   β”œβ”€β”€ server_cfg.py
β”‚   └── templates
└── yolov3_deepsort_eval.py

Dependencies

Expand

See this requirements.txt for more detail.

  • python 3 (python2 not sure)
  • numpy
  • scipy
  • opencv-python
  • sklearn
  • torch >= 0.4
  • torchvision >= 0.1
  • pillow
  • vizer
  • edict

Quick Start

Expand
  1. Check all dependencies installed
pip install -r requirements.txt

for user in china, you can specify pypi source to accelerate install like:

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. Clone this repository
git clone https://github.com/xuarehere/yolovx_deepsort_pytorch.git
  1. 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 ../../../
  1. 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 ../../../
  1. Compile nms module
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.

  1. (Optional) Prepare third party submodules

fast-reid

This library supports bagtricks, AGW and other mainstream ReID methods through providing an fast-reid adapter.

to prepare our bundled fast-reid, then follow instructions in its README to install it.

Please refer to configs/fastreid.yaml for a sample of using fast-reid. See Model Zoo for available methods and trained models.

MMDetection

This library supports Faster R-CNN and other mainstream detection methods through providing an MMDetection adapter.

to prepare our bundled MMDetection, then follow instructions in its README to install it.

Please refer to configs/mmdet.yaml for a sample of using MMDetection. See Model Zoo for available methods and trained models.

Run

git submodule update --init --recursive
  1. Run demo
usage: deepsort.py [-h]
                   [--fastreid]
                   [--config_fastreid CONFIG_FASTREID]
                   [--mmdet]
                   [--config_mmdetection CONFIG_MMDETECTION]
                   [--config_detection CONFIG_DETECTION]
                   [--config_deepsort CONFIG_DEEPSORT] [--display]
                   [--frame_interval FRAME_INTERVAL]
                   [--display_width DISPLAY_WIDTH]
                   [--display_height DISPLAY_HEIGHT] [--save_path SAVE_PATH]
                   [--cpu] [--camera CAM]
                   VIDEO_PATH         

# yolov3 + deepsort
python deepsort.py [VIDEO_PATH]

# yolov3_tiny + deepsort
python deepsort.py [VIDEO_PATH] --config_detection ./configs/yolov3_tiny.yaml

# yolov3 + deepsort on webcam
python3 deepsort.py /dev/video0 --camera 0

# yolov3_tiny + deepsort on webcam
python3 deepsort.py /dev/video0 --config_detection ./configs/yolov3_tiny.yaml --camera 0

# fast-reid + deepsort
python deepsort.py [VIDEO_PATH] --fastreid [--config_fastreid ./configs/fastreid.yaml]

# MMDetection + deepsort
python deepsort.py [VIDEO_PATH] --mmdet [--config_mmdetection ./configs/mmdet.yaml]


# yolov4 + deepsort on video
python3 deepsort.py ./001.avi --save_path ./output/yolov4/001 --config_detection ./configs/yolov4.yaml --detect_model yolov4


# yolov4Scaled + deepsort on video
python3 deepsort.py ./001.avi --save_path ./output/yolov4Scaled/001 --config_detection ./configs/yolov4Scaled.yaml --detect_model yolov4Scaled

# yolov5 + deepsort on video
python3 deepsort.py ./001.avi --save_path ./output/yolov5/001 --config_detection ./configs/yolov5.yaml --detect_model yolov5

# yolov6 + deepsort on video
python3 deepsort.py ./001.avi --save_path ./output/yolov6/001 --config_detection ./configs/yolov6.yaml --detect_model yolov6

# yolov7 + deepsort on video
python3 deepsort.py ./001.avi --save_path ./output/yolov7/001 --config_detection ./configs/yolov7.yaml --detect_model yolov7

# yolov8 + deepsort on video
python3 deepsort.py ./001.avi --save_path ./output/yolov8/001 --detect_model yolov8 --config_detection ./configs/yolov8.yaml 

# yolox + deepsort on video
python deepsort.py  ./001.avi --save_path ./output/yolox/001  --config_detection ./configs/yolox.yaml  --detect_model yolox 

# yolor + deepsort on video
python deepsort.py  ./001.avi --save_path ./output/yolor/001  --config_detection ./configs/yolor.yaml  --detect_model yolor 

# ppyoloe + deepsort on video
python deepsort.py  ./001.avi --save_path ./output/ppyoloe/001  --config_detection ./configs/ppyoloe.yaml  --detect_model ppyoloe 

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 passwd:fbuw

The Object model

Expand

Switch to model directory, see README.MD for more details.

For example:

cd detector/YOLOV5
# see detector/YOLOV5/README.md for more details

Training the Object model

see detector/{model}/README.md for more details.

For example:

cd detector/YOLOV5
python train.py --img 640 --data VOC.yaml --cfg yolov5s.yaml --weight ../../models/yolov5/yolov5s.pt --batch-size 64 --epochs 100

or See this link for more detail

Detect

see detector/{model}/README.md for more details.

cd detector/YOLOV5/
python  detect.py --source ../../001.avi --weights ../../models/yolov5/v4.0/yolov5s.pt --device 1

Validate

Validate a model's accuracy on datasets.

see detector/{model}/README.md for more details.

cd detector/YOLOV5/

python val.py --weights  ../../models/yolov5/v4.0/yolov5s.pt  --data coco.yaml  --img 640 --half

Training the RE-ID model

Expand

The original model used in paper is in original_model.py, and its parameter here original_ckpt.t7.

To train the model, first you need download Market1501 dataset or Mars dataset.

Then you can try train.py to train your own parameter and evaluate it using test.py and evaluate.py. train.jpg

Dataset

python prepare_data.py --data_dir {data_path}/Market-1501-v15.09.15

Train

$ cd ./deep_sort/deep/train.py

$ python train.py --data-dir /workspace/dataset/Market-1501/Market-1501-v15.09.15/pytorch/ --interval 10  --gpu-id 0

See this link for more detail

Demo videos and images

1.jpg

1.jpg

C ++

yolov5, v7

References

Expand