Coder Social home page Coder Social logo

adaobartolomeuab / detecting-tracking-and-counting-people Goto Github PK

View Code? Open in Web Editor NEW

This project forked from puchalas/detecting-tracking-and-counting-people

0.0 0.0 0.0 202.64 MB

Scope of this project is to use Yolov4 and Deep Sort implementation in Tensorflow to detect, track and count people getting on and off a metropolitan train

Python 100.00%

detecting-tracking-and-counting-people's Introduction

Table of contents

Introduction

Object tracking implemented with YOLOv4 (Keras), DeepSort (TensorFlow). YOLOv4 is a state of the art algorithm that uses deep convolutional neural networks to perform object detections. We can take the output of YOLOv4 feed these object detections into Deep SORT (Simple Online and Realtime Tracking with a Deep Association Metric) in order to create a highly accurate object tracker. Above pipeline was used on PAMELA-UANDES DATASET in order to detect, track and count people getting on and off a metropolitan train.

Requirements

pip install -r requirements.txt

Custom YOLOv4 weights

Our object tracker uses YOLOv4 to make the object detections, which deep sort then uses to track. There exists an official pre-trained YOLOv4 object detector model that is able to detect 80 classes. Unfortunately default detection fails when used on videos from PAMELA-UANDES DATASET. In order to fix that problem custom YOLO model had to be trained. Entire procedure is described here.

Running the Tracker with YOLOv4

All we need to do is run the object_tracker.py script to run our object tracker with YOLOv4 and DeepSort.

# Run yolov4 deep sort object tracker on video and print tracks statistics
python object_tracker.py --output outputs/output.avi --info

The output flag allows you to save the resulting video of the object tracker running so that you can view it again later. Video will be saved to the path that you set. (outputs folder is where it will be if you run the above command!)

As mentioned above, the resulting video will save to wherever you set the --output command line flag path to. I always set it to save to the 'outputs' folder. You can also change the type of video saved by adjusting the --output_format flag, by default it is set to AVI codec which is XVID.

Orginal YOLO vs Custom YOLO:

before after

Training custom yolo model

For creating custom yolov4 model Alex's Darknet was used. To start the procedure pamela-uandes dataset need to be downloaded. Videos have to be put in adequate folders data/dataset/video/test and data/dataset/video/train. Csv annotation files have to be put in data/dataset/annotations/test and data/dataset/annotations/train (these files are already in repo). To create images with proper yolo annotations run following command:

python ./tools/process_pamela.py

Then all you have to do is to follow instructions given in this notebook. The rest if needed custom config files are located in data/darknet_files.

Counting people

To enable counting run tracker with following command:

python object_tracker.py --output outputs/output.avi --count

As soon as the video starts processing you will be presented with the output widow. Then you will be able to choose 2 points on the screen creating virtual line. People crossing this line will be counted.

Create line:

line

Final output:

final

Evaluation

To evaluate detection AP first you need to run following commands:

#create txt files for every frame and process pamela ground truth files
python ./tools/create_files_for_evaluation.py 
#calculate mAP based on created files
python ./tools/calculate_map.py 

To evaluate detection metrics run following command:

python object_tracker.py --track_eval

PR curve:

PR

Command Line Args Reference

object_tracker.py:
  --[no]count: count people crossing the line the on screen
    (default: 'false')
  --[no]dont_show: dont show video output
    (default: 'false')
  --[no]info: show detailed info of tracked objects
    (default: 'false')
  --output: path to output video
  --output_format: codec used in VideoWriter when saving video to file
    (default: 'XVID')
  --[no]track_eval: enable tracking evaluation
    (default: 'false')
  --track_eval_gt_path: path to csv GT file from PAMELA dataset
    (default: 'data/dataset/annotations/train/A_d800mm_R1-Filt.csv')
  --video: path to input video or set to 0 for webcam
    (default: './data/video/test2.mpg')
  --weights: path to weights file
    (default: 'data/yolov4-custom_best.weights')
    
.\tools\process_pamela.py:
  --csv_dir: path to directory containing train and test annotations folders
    (default: 'data/dataset/annotations')
  --[no]dont_show: dont show video output
    (default: 'false')
  --output_dir: path to output video
    (default: './outputs')
  --output_format: codec used in VideoWriter when saving video to file
    (default: 'XVID')
  --output_images_dir: path to output video
    (default: 'data/dataset/images')
  --[no]save_GT_videos: save video with boxes from ground truth files
    (default: 'false')
  --size: resize images to
    (default: '416')
    (an integer)
  --video_dir: path to directory containing train and test video folders
    (default: 'data/dataset/video')

Credits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.