A real-time vehicle detection system using YOLOv5 and Streamlit for a user-friendly interface.
- Python 3.8 or higher
- CUDA-capable GPU (recommended)
- Git
- Clone the repository:
git clone [repository-url]
cd vehicle-detection-system- Create and activate virtual environment:
# Windows
python -m venv venv
.\venv\Scripts\activate
# Linux/Mac
python -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Download YOLOv5:
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt
cd ..-
Place your dataset in the project root directory. The expected structure is a folder named
trafic_datacontainingtrainandvalidsubdirectories, each withimagesandlabelsfolders. -
Run the label conversion script to convert original labels to YOLO format with the correct class mapping:
python convert_labels.py- Train the YOLOv5 model:
python yolov5/train.py --img 480 --batch 24 --epochs 30 --data data/dataset.yaml --weights yolov5/yolov5n.pt --workers 4 --cache(You can adjust parameters like --epochs and --batch as needed)
- Start the Streamlit app:
streamlit run app.py-
Open your browser and navigate to the provided local URL (usually
http://localhost:8501). -
Upload an image and adjust the confidence threshold for detection.
- Speed: Real-time detection capabilities
- Accuracy: State-of-the-art object detection
- Efficiency: Lightweight model (YOLOv5n) for faster processing
- Flexibility: Easy to train and fine-tune
- Base Model: YOLOv5n (nano)
- Input Size: 480x480 pixels
- Classes:
- Car
- Truck
- Bus
- Ambulance
- Motorbike
- Bicycle
- Training Parameters:
- Batch Size: 24
- Epochs: 30
- Learning Rate: Adaptive
- Optimizer: SGD with momentum
-
Image Preprocessing:
- Resize to 480x480
- Normalize pixel values
- Convert to tensor format
-
Feature Extraction:
- Convolutional layers
- Feature pyramid network
- Multi-scale detection
-
Post-processing:
- Non-maximum suppression
- Confidence thresholding
- Bounding box refinement
-
Performance:
- CPU-only mode is slower
- Minimum 4GB RAM required
- GPU recommended for real-time detection
-
Detection Accuracy:
- Works best with clear, well-lit images
- May struggle with:
- Extreme weather conditions
- Poor lighting
- Occluded vehicles
- Very small vehicles
-
Image Requirements:
- Minimum resolution: 480x480 pixels
- Supported formats: JPG, JPEG, PNG
- Maximum file size: 10MB
-
Vehicle Types:
- Trained to detect: Car, Truck, Bus, Ambulance, Motorbike, Bicycle
- Assumes vehicles are reasonably visible
-
Environment:
- Standard road/street scenes
- Moderate to good lighting conditions
- Vehicles are not heavily occluded
-
Usage:
- Single image processing
- Static images (not video)
- User can adjust confidence threshold
(Training metrics will be updated after training completion)
- Initial training attempts encountered issues with incorrect class IDs in labels, resolved by cleaning the conversion script and updating dataset paths.
- Performance may be limited on systems without a dedicated GPU.
-
Model Enhancements:
- Improve small object detection
- Better handling of occlusions
-
Features:
- Video processing support
- Real-time tracking
- Multiple model options
vehicle-detection-system/
├── app.py # Streamlit application
├── data/
│ ├── dataset.yaml # Dataset configuration
│ ├── images/ # Training and validation images (copied from trafic_data)
│ └── labels/ # Converted training and validation labels
├── yolov5/ # YOLOv5 framework
├── requirements.txt # Project dependencies
├── convert_labels.py # Script to convert original labels to YOLO format
├── .gitignore # Specifies intentionally untracked files
└── README.md # This file
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.


