This repository hosts a YOLO-powered computer vision prototype that spots fire and smoke in real time. It bundles:
webcam_inference.py– a live preview loop that highlights detections, mirrors consumer smart-home camera behavior, and plays an audible alarm when a confident fire signal appears.trainer.py– a GPU-first training harness that resolves dataset paths, resumes Ultralytics runs, and materializes adata.resolved.yamlfor deterministic experiments.- Roboflow-exported dataset stubs (
train/,valid/,test/anddata.yaml) plus example checkpoints (yolo11n.pt,yolov8s.pt) so you can fine-tune or evaluate immediately.
The codebase is meant as one of the early prototypes for a smart-home fire sensor:
- Validate whether RGB cameras can complement traditional flame/heat sensors before investing in custom hardware.
- Provide a reference implementation teams can wrap into a microservice, Home Assistant add-on, or edge gateway.
- Accelerate experimentation on alarm logic (e.g., what confidence threshold triggers sirens, when to mirror frames, how to log alerts).
- Ensure Python 3.10+ and a CUDA-capable GPU (trainer requires CUDA; inference can fall back to CPU).
- Install dependencies:
pip install -r requirements.txt
- (Optional) Drop any additional YOLO
.ptcheckpoints beside this README or underruns/*/weights/.
python webcam_inference.py \
--source 0 \
--mirror \
--fire-alert-threshold 0.85 \
--alarm-sound firealarm.mp3--sourceaccepts a camera index, video path, or RTSP/HTTP stream.- The script auto-selects the freshest
runs/*/weights/best.pt; override with--weights path/to/model.pt. - Audio alerts use
playsound; set--alarm-soundto a custom MP3/WAV or--alarm-sound ""to disable playback. - Press
qorEscto exit the preview window.
python trainer.py \
--data data.yaml \
--weights yolov8s.pt \
--epochs 50 \
--batch 16 \
--project runs \
--name smart-flame-detector- The trainer resolves the relative paths inside
data.yamland writesdata.resolved.yamlautomatically for Ultralytics. --devicedefaults to GPU0; pass--device 0,1for multi-GPU training.- Checkpoints land under
runs/<name>/weights/; pickbest.ptfor deployment and copy it besidewebcam_inference.pyif desired.
While this repository focuses on detection, the outputs are designed for downstream automation:
- Listen to the log stream (stdout) or extend
AlarmPlayerto call MQTT/webhooks whenfire_alert_thresholdis met. - Wrap
webcam_inference.pyin a service that exposes the annotated frames over RTSP/WebRTC for monitoring panels. - Export Ultralytics results to ONNX/TensorRT if the final hardware target is an embedded edge device.
data.yaml points to the Roboflow dataset firesensor-zwryw/fire-h2gkf-6mcdq (CC BY 4.0). Replace the train/, valid/, and test/ directories with your own captures to adapt the prototype to new environments or camera placements.
Use this README as the living blueprint for transforming the prototype into a production-ready smart-home fire sensor. Update it as you iterate on alarm logic, deployment targets, or dataset sources.