🚬 Smoking Detection β€” YOLOv8s

A fine-tuned YOLOv8s object detection model trained to detect cigarettes in images and video streams. Designed for real-world deployment with crash-resilient training and automatic checkpoint uploads to Hugging Face.


πŸ“Š Model Performance

YOLO Validation Metrics

Metric Score
mAP@50 0.8796
mAP@50-95 0.5198
Precision 0.9261
Recall 0.8814
F1 Score 0.9032

Image-Level Classification Report (307 validation images)

Class Precision Recall F1-Score Support
No Cigarette 0.8108 0.9677 0.8824 31
Cigarette 0.9963 0.9746 0.9853 276
Accuracy 0.9739 307
Macro Avg 0.9036 0.9712 0.9339 307
Weighted Avg 0.9776 0.9739 0.9749 307

Model Evaluation Metrics

Model Evaluation Metrics

Confusion Matrix Summary

Predicted: No Cigarette Predicted: Cigarette
True: No Cigarette 30 (96.77%) 1 (3.23%)
True: Cigarette 7 (2.54%) 269 (97.46%)

Confusion Matrix


πŸ—οΈ Training Setup

Dataset

  • Source: Roboflow β€” pro-hiyaw / cigarettes-reality-2-trnm2 (Version 1)
  • Format: YOLOv8 (yolo26)

Model

  • Base weights: yolo26s.pt
  • Architecture: YOLOv8 Small

Hyperparameters

Parameter Value
Epochs 200
Image size 800
Batch size 16
Device GPU 0
Patience (early stopping) 30

Data Augmentation

Augmentation Value
HSV Saturation (hsv_s) 0.2
HSV Value / Exposure (hsv_v) 0.2
Rotation (degrees) Β±10Β°
Horizontal Flip (fliplr) 0.5

πŸ”„ Crash-Resilient Training

The training pipeline includes automatic crash recovery:

  • At the end of every epoch, a training_status.json file is written with the current epoch, path to last.pt, and path to best.pt.
  • On restart, if a status file is found with "status": "training", training automatically resumes from the last saved weights.
  • Every 10 epochs, checkpoints are uploaded to Hugging Face:
    • weights/epoch_{N}_last.pt β€” rolling checkpoint
    • weights/best.pt β€” best model so far (overwritten each time)
    • training_status.json β€” current training state

πŸ€— Hugging Face Integration

Model checkpoints are automatically uploaded to a private Hugging Face repository during training.

  • Repo: <your-username>/Smoking-detection-YOLO26s
  • Visibility: Private
  • Upload frequency: Every 10 epochs

Authentication uses a Hugging Face token stored as a Kaggle secret (HF_TOKEN).


πŸš€ Quick Start

Install Dependencies

pip install ultralytics roboflow huggingface_hub opencv-python

Run Inference

from ultralytics import YOLO

model = YOLO("weights/best.pt")
results = model.predict(source="your_image.jpg", imgsz=800, conf=0.5)
results[0].show()

Resume Training

Simply re-run the training script. If training_status.json exists and points to valid weights, training will resume automatically from the last checkpoint.


πŸ“ Project Structure

.
β”œβ”€β”€ training_status.json        # Auto-generated crash recovery state
β”œβ”€β”€ runs/
β”‚   └── detect/
β”‚       └── train/
β”‚           └── weights/
β”‚               β”œβ”€β”€ best.pt     # Best checkpoint
β”‚               └── last.pt     # Latest checkpoint
└── <dataset>/
    └── data.yaml               # Dataset config (auto-downloaded from Roboflow)

πŸ” Required Secrets (Kaggle)

Secret Name Description
HF_TOKEN Hugging Face API token
RF Roboflow API key

πŸ“„ License

This project is for research and educational purposes. Dataset sourced from Roboflow Universe under its respective license.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support