π¬ 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
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%) |
ποΈ 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.jsonfile is written with the current epoch, path tolast.pt, and path tobest.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 checkpointweights/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.
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support

