wendys-llc commited on
Commit
2e5dcd3
·
verified ·
1 Parent(s): b5e3a2a

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +39 -87
README.md CHANGED
@@ -2,107 +2,59 @@
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
 
2
  license: apache-2.0
3
  tags:
4
  - image-classification
5
+ - transformers
 
6
  - pytorch
7
  datasets:
8
  - wendys-llc/chkbx
 
 
 
9
  ---
10
 
11
+ # Checkbox Classifier
12
 
13
+ Binary classifier for checkbox states (checked/unchecked).
 
14
 
15
+ ## Usage with Transformers
 
 
 
 
 
 
 
16
 
17
  ```python
18
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ # Load pipeline
21
+ classifier = pipeline("image-classification",
22
+ model="wendys-llc/checkbox-classifier",
23
+ trust_remote_code=True)
 
 
 
 
 
 
 
24
 
25
  # Predict
26
+ from PIL import Image
27
+ image = Image.open("checkbox.jpg")
28
+ result = classifier(image)
29
+ print(result)
30
+ # [
31
+ # {'label': 'checked', 'score': 0.99},
32
+ # {'label': 'unchecked', 'score': 0.01}
33
+ # ]
34
+ ```
 
 
 
 
35
 
36
+ ## Direct Usage
 
 
37
 
38
+ ```python
39
+ from transformers import AutoModelForImageClassification, AutoImageProcessor
40
+ import torch
41
+ from PIL import Image
42
+
43
+ model = AutoModelForImageClassification.from_pretrained(
44
+ "wendys-llc/checkbox-classifier",
45
+ trust_remote_code=True
46
+ )
47
+ processor = AutoImageProcessor.from_pretrained("wendys-llc/checkbox-classifier")
48
 
49
+ image = Image.open("checkbox.jpg")
50
+ inputs = processor(images=image, return_tensors="pt")
51
 
52
+ with torch.no_grad():
53
+ outputs = model(**inputs)
54
+ logits = outputs.logits
55
+ predicted_class = logits.argmax(-1).item()
56
+
57
+ print(model.config.id2label[predicted_class])
58
+ ```
59
 
60
+ ## Accuracy: 97.1%