Downloads · 30 days
0
dhruvguptaa/screen-on-off-classifier
screen-on-off-classifier is a image classification model from dhruvguptaa. Use it when you need a label for an image. The card lists the license as mit.
Ultra-lightweight CNN (~23K params) that classifies phone screen images as ON or OFF. Designed for real-time CPU inference (<1ms per frame).
Downloads · 30 days
0
Access
Public
Updated Apr 24, 2026
Repo size
233 KB
Likes
1
Public
Click a slice to open those files.
.pt130 KB · 48%
From the Hugging Face model README
Ultra-lightweight CNN (~23K params) that classifies phone screen images as ON or OFF. Designed for real-time CPU inference (<1ms per frame).
| Metric | Value |
|---|---|
| Accuracy | 1.0000 |
| Precision | 1.0000 |
| Recall | 1.0000 |
| F1 Score | 1.0000 |
| Parameters | 23,473 |
| Inference | <1ms (CPU) |
import numpy as np
import cv2
import torch
import torch.nn as nn
class ScreenClassifier(nn.Module):
def __init__(self):
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(1, 16, 3, padding=1, bias=False), nn.BatchNorm2d(16), nn.ReLU(True), nn.MaxPool2d(2),
nn.Conv2d(16, 32, 3, padding=1, bias=False), nn.BatchNorm2d(32), nn.ReLU(True), nn.MaxPool2d(2),
nn.Conv2d(32, 64, 3, padding=1, bias=False), nn.BatchNorm2d(64), nn.ReLU(True), nn.AdaptiveAvgPool2d(1),
)
self.classifier = nn.Sequential(nn.Flatten(), nn.Dropout(0.3), nn.Linear(64, 1))
def forward(self, x):
return self.classifier(self.features(x))
# Load
model = ScreenClassifier()
model.load_state_dict(torch.load("screen_classifier_best.pth", map_location="cpu", weights_only=True))
model.eval()
# Predict from OpenCV frame
frame = cv2.imread("phone_screen.jpg")
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
resized = cv2.resize(gray, (64, 64), interpolation=cv2.INTER_AREA)
tensor = torch.from_numpy(resized.astype(np.float32)).div(255.0)
tensor = (tensor - 0.5) / 0.5
tensor = tensor.unsqueeze(0).unsqueeze(0)
with torch.no_grad():
prob = torch.sigmoid(model(tensor).squeeze()).item()
label = "ON" if prob >= 0.5 else "OFF"
confidence = prob if label == "ON" else 1.0 - prob
print(f"{label} (confidence: {confidence:.1%})")
Trained on synthetic data (23473 params) with domain randomization.
screen_classifier_best.pth — PyTorch state dictscreen_classifier_best.pt — TorchScript (deploy without class definition)metrics.json — Training metricsscreen_classifier.py — Full training + inference code