AI Hard Hat Detector
AI Hard Hat Detector
Overiew
In 2024, I built a POC IoT device that would detect if a person was wearing a hard hat or not. It would then send a message via MQTT to another device that would display “GO” if they were wearing a hard hat or “STOP” if they were not. I loved this little project as it touched on AI/ML, IoT, and I learned some new technologies like MQTT. I’ve wanted to write up a post on this project, but I decided to redo the project itself and write that up here. This post will be updated as I go and potentially be split into multiple posts. If so, I will link them.
The Plan
Project Brief
Use an inexpensive IoT camera to detect if a person is wearing a hard hat or not.
Criteria
- Create synthetic data to train ML model
- Use Unreal Engine to create virtual people (MetaHumans) with and without hard hats
- Program camera movements to take pictures for training data
- IoT device must only message result, cannot offload detection
- Use MQTT to send pass/fail/noop messages
- Model must run on ESP32 device
- Must use GCP for model training
- A potential employer focuses on GCP for their clients, so I want to demonstrate my knowledge of that ecosystem
Phases
- Build synthetic dataset
- Prep Unreal Engine 5 environment
- Enable MetaHuman Creator plugin
- Create MetaHumans
- Use at least three for diversity
- Add cine camera and crane
- program sequence for crane movement over 150 frames
- Capture images
- Captured 150 frames (images) over three passes (low, medium, high crane height) per MetaHuman (3) with hard hat and again without (2)
- Resulting in 2,700 images
- Rename files for easy classification
- Prep Unreal Engine 5 environment
- Train model using GCP
- Create dataset “IsWearingHardHat”
- Created two lables, “hardhat” and “nohat”
- Upload to GCP
- Uploaded in batches of 500
- Labled for classification (versus object detection) as “nohat” and “hardhat”
- Using VertexAI and AutoML, set a 10 hour training budget for training an edge AI model (5.6MB higher accuracy)
- model failed to train the first two attempts, but for the 3rd time I set it to the 3.2MB size
- Download the tflite model file
- Create dataset “IsWearingHardHat”
- Deploy the model to ESP32 IoT device
This post is licensed under CC BY 4.0 by the author.