Computer vision project using YOLO to detect and classify Formula 1 teams in race images and videos. The project also estimates and visualizes the distance between cars in real-time, displaying the gap in both meters and seconds, enabling dynamic race analysis.
This repository contains code and notebooks for an AI-powered Formula 1 team detection system. Leveraging the YOLO (You Only Look Once) architecture, the model detects and classifies F1 team cars in images and videos with high accuracy. Additionally, it estimates the distance between cars, providing real-time gap metrics in both meters and seconds, enabling comprehensive racing analysis and visualization.
Note
To access the dataset, please visit: F1 Car 2023 Dataset
Warning
Some materials are excluded by .gitignore and not uploaded to this repository, including training results, cache files, and processed datasets. Generate them by running the provided notebooks.
- 🎯 YOLO-based Detection: Real-time identification and classification of Formula 1 cars by team
- 📏 Distance Estimation: Precise calculation and visualization of car-to-car distances (meters and seconds)
- 🎬 Result Visualization: Annotated real-time video output with team labels and gap information
- 🔍 False Positive Filtering: Intelligent system to eliminate ghost detections through overlap analysis
- 🏃 Object Tracking: Maintains consistent car identity throughout video sequences
- ⚙️ Custom Confidence Thresholds: Team-specific detection optimization
F1_AI_team_detection/
├── weights/ # Trained models and demo files
│ ├── f1_gif_2.gif # Demo animation
│ ├── fine_tuned.pt # Final optimized model
│ ├── yolo_medium_detection.pt # Fine-tuned medium YOLO model
│ └── yolo_small_detection.pt # Fine-tuned small YOLO model
├── .gitignore
├── LICENSE
├── README.md
├── YOLO_fine_tune.ipynb # Main YOLO training and fine-tuning notebook
├── data_augmentation.py # Training data augmentation script
└── gap_calculation.ipynb # Distance calculation and visualization notebook
The final optimized model achieved exceptional results across all metrics:
| Metric | Value |
|---|---|
| mAP50 | 0.940 |
| mAP50-95 | 0.781 |
| Precision | 0.925 |
| Recall | 0.771 |
| Team | Precision | Recall | mAP50 | mAP50-95 |
|---|---|---|---|---|
| Kick Sauber | 1.000 | 0.526 | 0.809 | 0.642 |
| Racing Bulls | 0.848 | 1.000 | 0.995 | 0.796 |
| Alpine | 1.000 | 0.447 | 0.962 | 0.851 |
| Ferrari | 1.000 | 0.819 | 0.995 | 0.910 |
| Haas | 0.881 | 1.000 | 0.995 | 0.895 |
| McLaren | 1.000 | 0.378 | 0.859 | 0.709 |
| Mercedes | 0.975 | 1.000 | 0.995 | 0.796 |
| Williams | 0.698 | 1.000 | 0.913 | 0.651 |
python 3.10+
torch 2.5.1
torchvision
ultralytics 8.3.137
opencv-python
numpy
pandas
jupyter
-
Clone the repository:
git clone https://github.com/VforVitorio/F1_AI_team_detection.git cd F1_AI_team_detection -
Install dependencies:
pip install torch torchvision ultralytics opencv-python numpy pandas jupyter
-
Download the dataset from Roboflow and place it in the
f1-dataset/directory.
- Open
YOLO_fine_tune.ipynbin Jupyter Notebook - Configure training parameters as needed
- Execute cells to train and fine-tune the YOLO model
- Monitor training progress and validation metrics
- Open
gap_calculation.ipynbnotebook - Set your video path for analysis
- Run the notebook to process videos and visualize results
- Output includes annotated videos with real-time distance calculations
- Use
data_augmentation.pyto expand your training dataset - Improves model robustness and performance
The system provides comprehensive race analysis by automatically calculating:
- 📐 Precise Distance Metrics: Real-time distance in meters between consecutive cars
- ⏱️ Time Gap Analysis: Conversion to time differences in seconds (based on 300 km/h reference speed)
- 🏁 Team Recognition: Accurate identification of all F1 teams with custom confidence thresholds
- 🎥 Live Visualization: Real-time visual labels and annotations
- 🚫 Ghost Detection Elimination: Advanced overlap analysis to filter false positives
- 🔄 Continuous Tracking: Maintains car identity throughout video sequences
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests to improve the project.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Roboflow for the F1 Car 2023 dataset
- Ultralytics for the YOLO implementation
- Formula 1 community for inspiration and testing
