Vehicles Counting using YOLOv4 + DeepSORT + Flask + Ngrok

Overview

Vehicles Counting using YOLOv4 + DeepSORT + Flask + Ngrok

🚙 🛵 🚛 🚌

A project for counting vehicles using YOLOv4 for training, DeepSORT for tracking, Flask for deploying to web (watch result purpose only) and Ngrok for public IP address

References

I want to give my big thanks to all of these authors' repo:

Getting Started

This project has 3 main parts:

  1. Preparing data
  2. Training model using the power of YOLOv4
  3. Implementing DeepSORT algorithm for counting vehicles

Preparing data

Preparing data notebook

I splitted my data into 2 scenes: daytime and nighttime, and training 8 classes (4 classes each scene, which are motorbike, car, bus, truck).

Prepare your own data or you can download my cleaned data with annotations:

If you prepare your own data, remember your annotation files fit this format:

  1. Every image has its own annotation file (.txt)
  2. Each file contains a list of objects' bounding box (read this for more details):

   
    
    
     
     
      
      
       
       
       
         ... 
       
      
      
     
     
    
    
   
   

Training model using YOLOv4

Training model notebook

Training model on your local computer is really complicated in environment installation and slow if you don't have a powerful GPU. In this case, I used Google Colab.

Read more: Testing your trained model on local machine with OpenCV

Implementing DeepSORT algorithm for counting vehicles

Implementing DeepSORT notebook

First, setting up environment on your machine:

Conda (Recommended)

# Tensorflow CPU
conda env create -f conda-cpu.yml
conda activate yolov4-cpu

# Tensorflow GPU
conda env create -f conda-gpu.yml
conda activate yolov4-gpu

Pip

(TensorFlow 2 packages require a pip version > 19.0.)

# TensorFlow CPU
pip install -r requirements.txt

# TensorFlow GPU
pip install -r requirements-gpu.txt

# Google Colab
!pip install -r requirements-colab.txt

Convert YOLOv4 model to Tensorflow Keras

Copy your trained model in previous part to this project and run save_model.py in cmd:

  • --weights: Path to .weights file (your trained model)
  • --output: Path to converted model.
  • --model: Model version (yolov4 in this case)
python save_model.py --weights ./yolov4_final.weights --output ./checkpoints/yolov4-416 --model yolov4

Download my .weights model if you want: GGDrive mirror

Counting now!

Import VehiclesCounting class in object_tracker.py file and using run() to start running:

# Import this main file
from object_tracker import VehiclesCounting
# Initialize
vc = VehiclesCounting(cam_name,
framework='tf', 
weights='./checkpoints/yolov4-416', 
size=416, 
tiny=False, 
model='yolov4', 
video='./data/video/test.mp4', 
output=None, 
output_format='XVID', 
iou=0.45, 
score=0.5, 
dont_show=False, 
info=False, 
count=False,
detect_line_position=0.5
detect_line_angle=0)
  • cam_name: input your camera name
  • framework: choose your model framework (tf, tflite, trt)
  • weights: path to your .weights
  • size: resize images to
  • tiny: (yolo,yolo-tiny)
  • model: (yolov3,yolov4)
  • video: path to your video or set 0 for webcam or youtube url
  • output: path to your results
  • output_format: codec used in VideoWriter when saving video to file
  • iou: iou threshold
  • score: score threshold
  • dont_show: dont show video output
  • info: show detailed info of tracked objects
  • count: count objects being tracked on screen
  • detect_line_position: (0..1) of height of video frame.
  • detect_line_angle: (0..180) degrees of detect line.
# Run it
vc.run()

Contact me

Owner
Duong Tran Thanh
I love learning AI and mobile development
Duong Tran Thanh
Several simple examples for popular neural network toolkits calling custom CUDA operators.

Neural Network CUDA Example Several simple examples for neural network toolkits (PyTorch, TensorFlow, etc.) calling custom CUDA operators. We provide

WeiYang 798 Jan 01, 2023
Adabelief-Optimizer - Repository for NeurIPS 2020 Spotlight "AdaBelief Optimizer: Adapting stepsizes by the belief in observed gradients"

AdaBelief Optimizer NeurIPS 2020 Spotlight, trains fast as Adam, generalizes well as SGD, and is stable to train GANs. Release of package We have rele

Juntang Zhuang 998 Dec 29, 2022
A very tiny, very simple, and very secure file encryption tool.

Picocrypt is a very tiny (hence "Pico"), very simple, yet very secure file encryption tool. It uses the modern ChaCha20-Poly1305 cipher suite as well

Evan Su 1k Dec 30, 2022
A PaddlePaddle implementation of Time Interval Aware Self-Attentive Sequential Recommendation.

TiSASRec.paddle A PaddlePaddle implementation of Time Interval Aware Self-Attentive Sequential Recommendation. Introduction 论文:Time Interval Aware Sel

Paddorch 2 Nov 28, 2021
Implementation of RegretNet with Pytorch

Dependencies are Python 3, a recent PyTorch, numpy/scipy, tqdm, future and tensorboard. Plotting with Matplotlib. Implementation of the neural network

Horris zhGu 1 Nov 05, 2021
A modification of Daniel Russell's notebook merged with Katherine Crowson's hq-skip-net changes

Edits made to this repo by Katherine Crowson I have added several features to this repository for use in creating higher quality generative art (featu

Paul Fishwick 10 May 07, 2022
Official release of MSHT: Multi-stage Hybrid Transformer for the ROSE Image Analysis of Pancreatic Cancer axriv: http://arxiv.org/abs/2112.13513

MSHT: Multi-stage Hybrid Transformer for the ROSE Image Analysis This is the official page of the MSHT with its experimental script and records. We de

Tianyi Zhang 53 Dec 27, 2022
Multiple types of NN model optimization environments. It is possible to directly access the host PC GUI and the camera to verify the operation. Intel iHD GPU (iGPU) support. NVIDIA GPU (dGPU) support.

mtomo Multiple types of NN model optimization environments. It is possible to directly access the host PC GUI and the camera to verify the operation.

Katsuya Hyodo 24 Mar 02, 2022
This repository contains the implementation of the paper Contrastive Instance Association for 4D Panoptic Segmentation using Sequences of 3D LiDAR Scans

Contrastive Instance Association for 4D Panoptic Segmentation using Sequences of 3D LiDAR Scans This repository contains the implementation of the pap

Photogrammetry & Robotics Bonn 40 Dec 01, 2022
Official implementation of "UCTransNet: Rethinking the Skip Connections in U-Net from a Channel-wise Perspective with Transformer"

[AAAI2022] UCTransNet This repo is the official implementation of "UCTransNet: Rethinking the Skip Connections in U-Net from a Channel-wise Perspectiv

Haonan Wang 199 Jan 03, 2023
PyTorch/GPU re-implementation of the paper Masked Autoencoders Are Scalable Vision Learners

Masked Autoencoders: A PyTorch Implementation This is a PyTorch/GPU re-implementation of the paper Masked Autoencoders Are Scalable Vision Learners: @

Meta Research 4.8k Jan 04, 2023
Res2Net for Instance segmentation and Object detection using MaskRCNN

Res2Net for Instance segmentation and Object detection using MaskRCNN Since the MaskRCNN-benchmark of facebook is deprecated, we suggest to use our mm

Res2Net Applications 55 Oct 30, 2022
Deep Learning for Human Part Discovery in Images - Chainer implementation

Deep Learning for Human Part Discovery in Images - Chainer implementation NOTE: This is not official implementation. Original paper is Deep Learning f

Shintaro Shiba 63 Sep 25, 2022
Angular & Electron desktop UI framework. Angular components for native looking and behaving macOS desktop UI (Electron/Web)

Angular Desktop UI This is a collection for native desktop like user interface components in Angular, especially useful for Electron apps. It starts w

Marc J. Schmidt 49 Dec 22, 2022
DA2Lite is an automated model compression toolkit for PyTorch.

DA2Lite (Deep Architecture to Lite) is a toolkit to compress and accelerate deep network models. ⭐ Star us on GitHub — it helps!! Frameworks & Librari

Sinhan Kang 7 Mar 22, 2022
M3DSSD: Monocular 3D Single Stage Object Detector

M3DSSD: Monocular 3D Single Stage Object Detector Setup pytorch 0.4.1 Preparation Download the full KITTI detection dataset. Then place a softlink (or

mumianyuxin 64 Dec 27, 2022
MusicYOLO framework uses the object detection model, YOLOx, to locate notes in the spectrogram.

MusicYOLO MusicYOLO framework uses the object detection model, YOLOX, to locate notes in the spectrogram. Its performance on the ISMIR2014 dataset, MI

Xianke Wang 2 Aug 02, 2022
This repository is an open-source implementation of the ICRA 2021 paper: Locus: LiDAR-based Place Recognition using Spatiotemporal Higher-Order Pooling.

Locus This repository is an open-source implementation of the ICRA 2021 paper: Locus: LiDAR-based Place Recognition using Spatiotemporal Higher-Order

Robotics and Autonomous Systems Group 96 Dec 15, 2022
Shōgun

The SHOGUN machine learning toolbox Unified and efficient Machine Learning since 1999. Latest release: Cite Shogun: Develop branch build status: Donat

Shōgun ML 2.9k Jan 04, 2023
Unsupervised captioning - Code for Unsupervised Image Captioning

Unsupervised Image Captioning by Yang Feng, Lin Ma, Wei Liu, and Jiebo Luo Introduction Most image captioning models are trained using paired image-se

Yang Feng 207 Dec 24, 2022