Skip to content

Fine-tuning YOLOv8n model on crowded scenes to count people or cars more accurately

Notifications You must be signed in to change notification settings

SepehrNoey/Fine-Tuning-YOLOv8n-for-Enhanced-Detection

Repository files navigation

Fine-Tuning YOLOv8 for Enhanced Detection in Crowded Scenes

This project fine-tunes the YOLOv8n model on a custom dataset of crowded scenes with more cars and pedestrians. The goal was to improve the model's ability to detect and count vehicles and pedestrians in busy environments. After training for 100 epochs, the model showed some improvements over the pre-trained version in specific settings, though some misclassifications and overcounting still occur, requiring further training for more accuracy.

Demo

Below is a comparison video between the pre-trained YOLOv8n model and the fine-tuned model on a custom dataset of crowded scenes:

  • Fine-Tuned YOLOv8n: Detects more cars and pedestrians in crowded scenes.
  • Pre-Trained YOLOv8n: Misses several objects in similar scenes.

Pedestrian Zones

Fine-Tuned Model Output Pre-trained Model Output
fine_tuned_yolov8n_video9.mp4
yolov8n_video9.mp4
fine_tuned_yolov8n_video3.mp4
yolov8n_video3.mp4

Traffic Scenes

Fine-Tuned Model Output Pre-trained Model Output
fine_tuned_yolov8n_video2.mp4
yolov8n_video2.mp4
fine_tuned_yolov8n_video7.mp4
yolov8n_video7.mp4
fine_tuned_yolov8n_video4.mp4
yolov8n_video4.mp4

Dataset and Labeling

The custom dataset was created by gathering images of crowded scenes and labeling the following object classes using the labelImg tool:

  • person
  • bicycle
  • car
  • truck

This step allowed for accurate fine-tuning of the YOLOv8n model to improve detection performance on these specific categories.

Model Fine-Tuning

The pre-trained YOLOv8n model was fine-tuned on the custom dataset for 100 epochs. This process improved its accuracy in crowded scenes, particularly in detecting pedestrians. As shown in the chart, the overall loss has reduced over the epochs and led to improved accuracy. Code of this part can be seen at trainer.py

results

Object Counting

After fine-tuning the model, some tools provided by the Ultralytics YOLO library to count object in video sequences have been used. The code of this part can be seen at counter.py.

Models Checkpoints

  • fine_tuned_yolov8n.pt: This is the best checkpoint of the fine-tuned model. Weights and other arguments can be found at runs/detect/train
  • yolov8n.pt: This is the base checkpoint used for fine-tuning on custom dataset, which is available at Ultralytics YOLO.

About

Fine-tuning YOLOv8n model on crowded scenes to count people or cars more accurately

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages