This repository demonstrates object detection using the YOLOv8 model for detecting persons and personal protective equipment (PPE) such as hard hats, gloves, masks, and more. The project covers both the conversion of PascalVOC annotations to YOLO format and the implementation of the YOLOv8 model for object detection.
- Overview
- Dataset Preparation
- YOLOv8 Model Training
- Inference and Prediction
- Visualization
- Results
- Installation
- Usage
- Acknowledgments
This project aims to detect persons and various PPE items using a custom-trained YOLOv8 model. It includes:
- Converting XML annotations from the PascalVOC format to YOLO format.
- Training a YOLOv8 model on a custom dataset.
- Making predictions and visualizing the results with bounding boxes.
The dataset annotations provided in PascalVOC XML format need to be converted to YOLO format for training the YOLOv8 model. The conversion ensures that the annotations are in the required format for YOLO, where each line in the .txt
file corresponds to an object in the image with normalized bounding box coordinates.
- The PascalVOC XML files should be stored in a directory (e.g.,
/XML_Labels
). - The converted YOLO annotations are saved in a separate directory (e.g.,
/labels
).
Once the dataset is prepared, the YOLOv8 model is trained using a custom dataset of images containing persons and PPE items. The dataset should include images and corresponding YOLO-format labels.
The model supports detection of the following classes:
- Person
- Hard-hat
- Gloves
- Mask
- Glasses
- Boots
- Vest
- PPE-suit
- Ear-protector
- Safety-harness
The training script handles loading images and annotations, training the model, and saving the best weights for later inference.
After training, the model can be used to make predictions on new images. The model outputs bounding boxes around detected objects, along with confidence scores and class labels.
The supported classes include:
- Person
- Hard-hat
- Gloves
- Mask
- Glasses
- Boots
- Vest
- PPE-suit
- Ear-protector
- Safety-harness
The project includes a visualization component that allows users to see the predictions overlaid on the input image. Bounding boxes are drawn around detected objects with labels indicating the class and confidence score.
The visualized image shows:
- Bounding boxes around detected objects.
- Class labels and confidence scores for each detected object.
The project demonstrates the effectiveness of YOLOv8 for detecting persons and PPE items. Results include high-confidence detections for various safety equipment in real-world images.
-
Clone the repository:
git clone https://github.com/your-username/your-repo-name.git cd your-repo-name
-
Install the necessary dependencies:
pip install -r requirements.txt
-
Install the YOLOv8 model framework:
pip install ultralytics
- Prepare your dataset by converting annotations to YOLO format.
- Train the YOLOv8 model on your dataset.
- Use the trained model to perform inference and visualize the predictions.
- Convert annotations: [Instruction]
- Train the model: [Instruction]
- Make predictions: [Instruction]
This project uses the YOLOv8 framework for object detection. Special thanks to Ultralytics for providing this powerful tool for object detection tasks.