Ensuring safety in industrial environments is paramount, and it's crucial to verify that workers adhere to safety protocols in real time. Traditional methods rely on overlay techniques that determine the intersection of the head and helmet, which demand substantial processing power. Is it feasible to achieve this without extensive computational resources? Absolutely, and I'll explain how I tackled this challenge!
To foster a safety-oriented culture, our client aims to develop a computer vision model that can identify whether a worker is wearing a hardhat and interact with them based on safety protocols. The initial version of this model utilized an overlay technique involving two objects: the person and the hardhat. However, this approach proved to be computationally intensive and less effective than intended.
- Incorrect Identification: The overlay of the body and helmet often inaccurately indicated helmet usage, failing to recognize situations where helmets were not worn properly.
- Performance Issues: The model's high computational requirements resulted in slow processing speeds, hindering real-time applicability.
In this project, I'll demonstrate a more efficient solution leveraging the YOLOv8 model, which significantly reduces computational demands while improving accuracy and speed.
It works well in various scenarios, including:
- Single Person with Hardhat:
- Person doesn't wear the Hardhat but holds it in hands:
- Angles from the top:
- Hardhat without a person won't be detected, person must wear it!
To create a robust model capable of accurately detecting hardhats in an industrial setting, I undertook a comprehensive dataset collection and preparation process:
-
Data Collection:
- Gathered a diverse set of images from the internet, including:
- People wearing hardhats.
- People without hardhats.
- Various hairstyles.
- Different types of safety helmets (e.g., for bicycles, motorbikes).
- Ensured the dataset contained a variety of scenarios to improve the model's ability to distinguish factory hardhats from other helmet types.
- Gathered a diverse set of images from the internet, including:
-
Data Annotation:
- Manually annotated each image to mark the presence of hardhats. This meticulous process involved:
- Labeling images with hardhats.
- Labeling images without hardhats.
- Excluding other types of helmets to ensure the model focuses solely on factory hardhats.
- Manually annotated each image to mark the presence of hardhats. This meticulous process involved:
Utilized the YOLOv8 model, a state-of-the-art object detection algorithm, to train our hardhat detection model:
-
Framework and Tools:
- Employed the Ultralytics library in Python for model training, which provides an efficient and user-friendly interface for implementing YOLO models.
-
Training Process:
- Split the annotated dataset into training and validation sets to evaluate the model's performance.
- Configured the YOLOv8 model with appropriate hyperparameters to optimize detection accuracy and speed.
- Trained the model on the annotated dataset, allowing it to learn and distinguish between workers with and without hardhats.
By following this approach, I developed a highly efficient hardhat detection model that operates with minimal computational resources, ensuring real-time applicability in industrial settings.
To run this project locally, follow these steps:
-
Clone this repository:
git clone [email protected]:Danil-Zhuravlov/hardhat-detection-yolov8.git
-
Create a virtual envinronment:
python -m venv venv
-
Select the virtual environment:
source venv/bin/activate
or for Windows:
venv\Scripts\activate
-
Install PyTorch and the required libraries listed in
requirements.txt
.pip install -r requirements.txt
-
Run
main.py
:python main.py
-
Gather enough images for the training dataset and put them in
dataset/images/train/
(current model trained on set of ~500 images) -
Annotate images, save in Yolo format, and put the annotations in
dataset/labels/train/
-
Open
config.yaml
and ensure you set the right index and class name based on your annotations. -
Edit
train.py
file by specifying the amount of epochs. 50-100 epochs are recommended for the best result. (It will take some time if you run locally) -
Move
best.pt
file fromruns/detect/train/weights
tohardhat-detection-yolov8/
folder, and replace the file. -
Run
main.py
:python main.py
- Train the model using 100 epochs instead of 50.
- Increase the amount of images with different environments and angles.
- Create an app.