/vehicle-counting

Vehicle counting using Pytorch

Primary LanguagePython

🏍️ πŸš™ Vehicle Tracking using YOLOv5 + DeepSORT 🚌

UPDATE 16.07.2021 - BIG REFACTOR

Code is cleaned and working fine now, promise 🀞

Method

  • Use YOLOv5 or EfficientDet for vehicle detection task, only considers objects in Region of Interest (ROI)
  • Use DeepSORT for car tracking, not need to retrain this model, only inference
  • Use Cosine Similarity to assign object's tracks to most similar directions.
  • Count each type of vehicle on each direction.

πŸ“” Notebook

  • For inference, use this notebook Notebook
  • To retrain detection model, follow instructions from my template

Results

screen
screen

Dataset

  • AIC-HCMC-2020: link
  • Direction and ROI annotation format:
cam_01.json # match video name
{
    "shapes": [
        {
            "label": "zone",
            "points": [[x1,y1], [x2,y2], [x3,y3], [x4,y4], ... ] #Points of a polygon
        },
        {
            "label": "direction01",
            "points": [[x1,y1], [x2,y2]] #Points of vector
        },
        {
            "label": "direction{id}",
            "points": [[x1,y1], [x2,y2]]
        },...
    ],
}
screen

πŸ₯‡ Pretrained weights

  • Download finetuned models from on AIC-HCMC-2020 dataset:
Model Image Size Weights MAP-S MAP-M MAP-L ALL
EfficientDet-D2 640x640 link 0.061 0.456 0.475 0.451
YOLOv5s 640x640 link 0.17 0.466 0.487 0.466
YOLOv5m 640x640 link 0.187 0.487 0.501 0.481

🌟 Inference

  • File structure
this repo
β”‚   detect.py
└───configs
β”‚      configs.yaml           # Contains model's configurations
β”‚      cam_configs.yaml       # Contains DEEPSORT's configuration for each video
  • Install dependencies by pip install -r requirements.txt
  • To run full pipeline:
python run.py --input_path=<input video or dir> --output_path=<output dir> --weight=<trained weight>
  • Extra Parameters:
    • --min_conf: minimum confident for detection
    • --min_iou: minimum iou for detection

References