Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- checkbox-detection
|
| 6 |
+
- computer-vision
|
| 7 |
+
- pytorch
|
| 8 |
+
datasets:
|
| 9 |
+
- wendys-llc/chkbx
|
| 10 |
+
metrics:
|
| 11 |
+
- accuracy
|
| 12 |
+
library_name: pytorch
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Checkbox State Classifier
|
| 16 |
+
|
| 17 |
+
This model classifies whether a checkbox is checked or
|
| 18 |
+
unchecked.
|
| 19 |
+
|
| 20 |
+
## Model Details
|
| 21 |
+
- **Architecture**: EfficientNetV2-S (PyTorch)
|
| 22 |
+
- **Input Size**: 128x128 RGB images
|
| 23 |
+
- **Output**: Binary classification (unchecked: 0, checked: 1)
|
| 24 |
+
- **Validation Accuracy**: 97.1%
|
| 25 |
+
- **Training**: Mixed precision on A100 GPU
|
| 26 |
+
|
| 27 |
+
## Quick Start
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
import torch
|
| 31 |
+
from PIL import Image
|
| 32 |
+
from torchvision import transforms
|
| 33 |
+
from huggingface_hub import hf_hub_download
|
| 34 |
+
import torch.nn as nn
|
| 35 |
+
from torchvision.models import efficientnet_v2_s,
|
| 36 |
+
EfficientNet_V2_S_Weights
|
| 37 |
+
|
| 38 |
+
# Define model architecture
|
| 39 |
+
class EfficientNetV2Classifier(nn.Module):
|
| 40 |
+
def __init__(self, num_classes=2, dropout_rate=0.3):
|
| 41 |
+
super().__init__()
|
| 42 |
+
self.backbone = efficientnet_v2_s(weights=EfficientNet
|
| 43 |
+
_V2_S_Weights.IMAGENET1K_V1)
|
| 44 |
+
num_features = self.backbone.classifier[1].in_features
|
| 45 |
+
self.backbone.classifier = nn.Sequential(
|
| 46 |
+
nn.Dropout(dropout_rate),
|
| 47 |
+
nn.Linear(num_features, 512),
|
| 48 |
+
nn.SiLU(inplace=True),
|
| 49 |
+
nn.BatchNorm1d(512),
|
| 50 |
+
nn.Dropout(dropout_rate),
|
| 51 |
+
nn.Linear(512, 256),
|
| 52 |
+
nn.SiLU(inplace=True),
|
| 53 |
+
nn.BatchNorm1d(256),
|
| 54 |
+
nn.Dropout(dropout_rate/2),
|
| 55 |
+
nn.Linear(256, num_classes)
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
def forward(self, x):
|
| 59 |
+
return self.backbone(x)
|
| 60 |
+
|
| 61 |
+
# Download and load model
|
| 62 |
+
model_path = hf_hub_download(repo_id="wendys-llc/checkbox-classifier",
|
| 63 |
+
filename="checkbox_classifier.pth")
|
| 64 |
+
checkpoint = torch.load(model_path, map_location='cpu')
|
| 65 |
+
|
| 66 |
+
model = EfficientNetV2Classifier(num_classes=2)
|
| 67 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 68 |
+
model.eval()
|
| 69 |
+
|
| 70 |
+
# Image preprocessing
|
| 71 |
+
transform = transforms.Compose([
|
| 72 |
+
transforms.Resize((128, 128)),
|
| 73 |
+
transforms.ToTensor(),
|
| 74 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406],
|
| 75 |
+
std=[0.229, 0.224, 0.225])
|
| 76 |
+
])
|
| 77 |
+
|
| 78 |
+
# Predict
|
| 79 |
+
def predict(image_path):
|
| 80 |
+
image = Image.open(image_path).convert('RGB')
|
| 81 |
+
input_tensor = transform(image).unsqueeze(0)
|
| 82 |
+
|
| 83 |
+
with torch.no_grad():
|
| 84 |
+
output = model(input_tensor)
|
| 85 |
+
probabilities = torch.nn.functional.softmax(output,
|
| 86 |
+
dim=1)
|
| 87 |
+
predicted = torch.argmax(probabilities, dim=1).item()
|
| 88 |
+
confidence = probabilities[0][predicted].item()
|
| 89 |
+
|
| 90 |
+
labels = {0: "unchecked", 1: "checked"}
|
| 91 |
+
return labels[predicted], confidence
|
| 92 |
+
|
| 93 |
+
# Example usage
|
| 94 |
+
result, conf = predict("checkbox.jpg")
|
| 95 |
+
print(f"Result: {result} (confidence: {conf:.1%})")
|
| 96 |
+
|
| 97 |
+
Training Dataset
|
| 98 |
+
|
| 99 |
+
Trained on https://huggingface.co/datasets/wendys-llc/chkbx
|
| 100 |
+
dataset containing ~6,000 annotated checkbox images.
|
| 101 |
+
|
| 102 |
+
Limitations
|
| 103 |
+
|
| 104 |
+
- Trained specifically on UI checkboxes, may not work well on
|
| 105 |
+
hand-drawn checkmarks
|
| 106 |
+
- Best performance on clear, high-contrast checkbox images
|
| 107 |
+
- Input images are resized to 128x128, very small checkboxes
|
| 108 |
+
may lose detail
|