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
HCQ: Hybrid Contrastive Quantization for Efficient Cross-View Video Retrieval

HCQ: Hybrid Contrastive Quantization for Efficient Cross-View Video Retrieval [toc] 1. Introduction This repository provides the code for our paper at

13 Dec 08, 2022
A Python library for Deep Graph Networks

PyDGN Wiki Description This is a Python library to easily experiment with Deep Graph Networks (DGNs). It provides automatic management of data splitti

Federico Errica 194 Dec 22, 2022
GBK-GNN: Gated Bi-Kernel Graph Neural Networks for Modeling Both Homophily and Heterophily

GBK-GNN: Gated Bi-Kernel Graph Neural Networks for Modeling Both Homophily and Heterophily Abstract Graph Neural Networks (GNNs) are widely used on a

10 Dec 20, 2022
Testability-Aware Low Power Controller Design with Evolutionary Learning, ITC2021

Testability-Aware Low Power Controller Design with Evolutionary Learning This repo contains the source code of Testability-Aware Low Power Controller

Lee Man 1 Dec 26, 2021
3D HourGlass Networks for Human Pose Estimation Through Videos

3D-HourGlass-Network 3D CNN Based Hourglass Network for Human Pose Estimation (3D Human Pose) from videos. This was my summer'18 research project. Dis

Naman Jain 51 Jan 02, 2023
Liver segmentation using MONAI and pytorch

Machine Learning use case in the field of Healthcare. In this project MONAI and pytorch frameworks are used for 3D Liver segmentation.

Abhishek Gajbhiye 2 May 30, 2022
Barlow Twins and HSIC

Barlow Twins and HSIC Unofficial Pytorch implementation for Barlow Twins and HSIC_SSL on small datasets (CIFAR10, STL10, and Tiny ImageNet). Correspon

Yao-Hung Hubert Tsai 49 Nov 24, 2022
CATE: Computation-aware Neural Architecture Encoding with Transformers

CATE: Computation-aware Neural Architecture Encoding with Transformers Code for paper: CATE: Computation-aware Neural Architecture Encoding with Trans

16 Dec 27, 2022
Learning Tracking Representations via Dual-Branch Fully Transformer Networks

Learning Tracking Representations via Dual-Branch Fully Transformer Networks DualTFR ⭐ We achieves the runner-ups for both VOT2021ST (short-term) and

phiphi 19 May 04, 2022
The first public PyTorch implementation of Attentive Recurrent Comparators

arc-pytorch PyTorch implementation of Attentive Recurrent Comparators by Shyam et al. A blog explaining Attentive Recurrent Comparators Visualizing At

Sanyam Agarwal 150 Oct 14, 2022
Official PyTorch implementation of "Proxy Synthesis: Learning with Synthetic Classes for Deep Metric Learning" (AAAI 2021)

Proxy Synthesis: Learning with Synthetic Classes for Deep Metric Learning Official PyTorch implementation of "Proxy Synthesis: Learning with Synthetic

NAVER/LINE Vision 30 Dec 06, 2022
Implicit Graph Neural Networks

Implicit Graph Neural Networks This repository is the official PyTorch implementation of "Implicit Graph Neural Networks". Fangda Gu*, Heng Chang*, We

Heng Chang 48 Nov 29, 2022
[NeurIPS 2021] Well-tuned Simple Nets Excel on Tabular Datasets

[NeurIPS 2021] Well-tuned Simple Nets Excel on Tabular Datasets Introduction This repo contains the source code accompanying the paper: Well-tuned Sim

52 Jan 04, 2023
Combining Reinforcement Learning and Constraint Programming for Combinatorial Optimization

Hybrid solving process for combinatorial optimization problems Combinatorial optimization has found applications in numerous fields, from aerospace to

117 Dec 13, 2022
Collection of NLP model explanations and accompanying analysis tools

Thermostat is a large collection of NLP model explanations and accompanying analysis tools. Combines explainability methods from the captum library wi

126 Nov 22, 2022
robomimic: A Modular Framework for Robot Learning from Demonstration

robomimic [Homepage]   [Documentation]   [Study Paper]   [Study Website]   [ARISE Initiative] Latest Updates [08/09/2021] v0.1.0: Initial code and pap

ARISE Initiative 178 Jan 05, 2023
Towards Debiasing NLU Models from Unknown Biases

Towards Debiasing NLU Models from Unknown Biases Abstract: NLU models often exploit biased features to achieve high dataset-specific performance witho

Ubiquitous Knowledge Processing Lab 22 Jun 14, 2022
Pull sensitive data from users on windows including discord tokens and chrome data.

⭐ For a 🍪 Pegasus Pull sensitive data from users on windows including discord tokens and chrome data. Features 🟩 Discord tokens 🟩 Geolocation data

Addi 44 Dec 31, 2022
DanceTrack: Multiple Object Tracking in Uniform Appearance and Diverse Motion

DanceTrack DanceTrack is a benchmark for tracking multiple objects in uniform appearance and diverse motion. DanceTrack provides box and identity anno

260 Dec 28, 2022
Pure python PEMDAS expression solver without using built-in eval function

pypemdas Pure python PEMDAS expression solver without using built-in eval function. Supports nested parenthesis. Supported operators: + - * / ^ Exampl

1 Dec 22, 2021