Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,104 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
metrics:
|
6 |
+
- accuracy
|
7 |
+
library_name: adapter-transformers
|
8 |
+
pipeline_tag: image-to-text
|
9 |
+
---
|
10 |
+
# Model Card for Pixelated Captcha Digit Detection
|
11 |
+
|
12 |
+
## Model Details
|
13 |
+
|
14 |
+
- **License:** Apache-2.0
|
15 |
+
- **Developed by:** Saidi Souhaieb
|
16 |
+
- **Finetuned from model:** YOLOv8
|
17 |
+
|
18 |
+
## Uses
|
19 |
+
|
20 |
+
This model is designed to detect pixelated captcha digits by showing bounding boxes and extracting the coordinates of the detections.
|
21 |
+
|
22 |
+
## How to Get Started with the Model
|
23 |
+
|
24 |
+
```python
|
25 |
+
import torch
|
26 |
+
import torch.nn as nn
|
27 |
+
import torch.optim as optim
|
28 |
+
from torch.utils.data import DataLoader
|
29 |
+
import torchvision.transforms as transforms
|
30 |
+
from torchvision.datasets import ImageFolder
|
31 |
+
from tqdm import tqdm
|
32 |
+
from PIL import Image
|
33 |
+
import torch.nn.functional as F
|
34 |
+
import os
|
35 |
+
|
36 |
+
class CNN(nn.Module):
|
37 |
+
def __init__(self):
|
38 |
+
super(CNN, self).__init__()
|
39 |
+
self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
|
40 |
+
self.conv2 = nn.Conv2d(16, 32, kernel_size=3, stride=1, padding=1)
|
41 |
+
self.conv3 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1)
|
42 |
+
self.pool = nn.MaxPool2d(2, 2)
|
43 |
+
self.fc1 = nn.Linear(64 * 4 * 4, 500)
|
44 |
+
self.fc2 = nn.Linear(500, 10) # 10 classes for example
|
45 |
+
|
46 |
+
def forward(self, x):
|
47 |
+
x = self.pool(F.relu(self.conv1(x)))
|
48 |
+
x = self.pool(F.relu(self.conv2(x)))
|
49 |
+
x = self.pool(F.relu(self.conv3(x)))
|
50 |
+
x = x.view(-1, 64 * 4 * 4)
|
51 |
+
x = F.relu(self.fc1(x))
|
52 |
+
x = self.fc2(x)
|
53 |
+
return x
|
54 |
+
|
55 |
+
transform = transforms.Compose([
|
56 |
+
transforms.Resize((32, 32)), # Adjust the size accordingly
|
57 |
+
transforms.ToTensor(),
|
58 |
+
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
59 |
+
])
|
60 |
+
|
61 |
+
transform = transforms.Compose([
|
62 |
+
transforms.Resize((32, 32)), # Adjust the size accordingly
|
63 |
+
transforms.ToTensor(),
|
64 |
+
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
|
65 |
+
])
|
66 |
+
|
67 |
+
model = CNN()
|
68 |
+
model.load_state_dict(torch.load('models/99acc_model.pth'))
|
69 |
+
|
70 |
+
def predict_number(folder_path):
|
71 |
+
"""
|
72 |
+
Predict the numbers in the images in the folder
|
73 |
+
"""
|
74 |
+
predict_numbers = []
|
75 |
+
for file in os.listdir(folder_path):
|
76 |
+
input_image = Image.open(f"temp/{file}").convert('RGB')
|
77 |
+
# Load and preprocess the input image
|
78 |
+
input_tensor = transform(input_image)
|
79 |
+
input_batch = input_tensor.unsqueeze(0) # Add a batch dimension
|
80 |
+
|
81 |
+
# Perform inference
|
82 |
+
with torch.no_grad():
|
83 |
+
output = model(input_batch)
|
84 |
+
|
85 |
+
# Get the predicted class label
|
86 |
+
_, predicted = torch.max(output, 1)
|
87 |
+
|
88 |
+
# Print the predicted class label
|
89 |
+
print("Predicted class label:", predicted.item(), "file", file)
|
90 |
+
predict_numbers.append(predicted.item())
|
91 |
+
|
92 |
+
return predict_numbers
|
93 |
+
|
94 |
+
```
|
95 |
+
|
96 |
+
## Training Details
|
97 |
+
|
98 |
+
### Training Data
|
99 |
+
|
100 |
+
Pixel Digit Captcha Data []
|
101 |
+
|
102 |
+
## Model Card Authors
|
103 |
+
|
104 |
+
[Saidi Souhaieb]
|