Sarjinkhan2003 commited on
Commit
94b866a
·
verified ·
1 Parent(s): 76eca0e

Classifier v2 architecture trained on real ICDAR MLT crops

Browse files
Files changed (1) hide show
  1. classifier/shobdo_classifier.py +10 -12
classifier/shobdo_classifier.py CHANGED
@@ -2,22 +2,20 @@ import torch
2
  import torch.nn as nn
3
 
4
  class ScriptClassifier(nn.Module):
5
- # ShobdoOCR Script Classifier
6
- # 23K parameters, <0.3MB
7
- # Input: (B, 1, 64, 256) normalized grayscale
8
- # Output: (B, 2) logits [0=Bengali, 1=English]
9
- # Routing threshold: conf >= 0.70
10
  def __init__(self):
11
  super().__init__()
12
  self.features = nn.Sequential(
13
- nn.Conv2d(1, 16, 3, padding=1), nn.BatchNorm2d(16), nn.ReLU(True), nn.MaxPool2d(2),
14
- nn.Conv2d(16, 32, 3, padding=1), nn.BatchNorm2d(32), nn.ReLU(True), nn.MaxPool2d(2),
15
- nn.Conv2d(32, 64, 3, padding=1), nn.BatchNorm2d(64), nn.ReLU(True), nn.MaxPool2d(2),
16
- nn.Conv2d(64, 64, 3, padding=1), nn.BatchNorm2d(64), nn.ReLU(True),
17
- nn.AdaptiveAvgPool2d((1, 1)),
18
  )
19
  self.classifier = nn.Sequential(
20
- nn.Flatten(), nn.Dropout(0.3), nn.Linear(64, 2)
21
  )
22
  def forward(self, x):
23
  return self.classifier(self.features(x))
@@ -25,4 +23,4 @@ class ScriptClassifier(nn.Module):
25
  with torch.no_grad():
26
  probs = torch.softmax(self.forward(x), dim=1)
27
  conf, pred = probs.max(dim=1)
28
- return ['bengali', 'english'][pred.item()], conf.item()
 
2
  import torch.nn as nn
3
 
4
  class ScriptClassifier(nn.Module):
5
+ # ShobdoOCR Script Classifier v2
6
+ # Trained on real ICDAR MLT crops + hard-augmented synthetic
7
+ # 23K parameters | conf_threshold=0.70
 
 
8
  def __init__(self):
9
  super().__init__()
10
  self.features = nn.Sequential(
11
+ nn.Conv2d(1,16,3,padding=1), nn.BatchNorm2d(16), nn.ReLU(True), nn.MaxPool2d(2),
12
+ nn.Conv2d(16,32,3,padding=1), nn.BatchNorm2d(32), nn.ReLU(True), nn.MaxPool2d(2),
13
+ nn.Conv2d(32,64,3,padding=1), nn.BatchNorm2d(64), nn.ReLU(True), nn.MaxPool2d(2),
14
+ nn.Conv2d(64,64,3,padding=1), nn.BatchNorm2d(64), nn.ReLU(True),
15
+ nn.AdaptiveAvgPool2d((1,1)),
16
  )
17
  self.classifier = nn.Sequential(
18
+ nn.Flatten(), nn.Dropout(0.3), nn.Linear(64,2)
19
  )
20
  def forward(self, x):
21
  return self.classifier(self.features(x))
 
23
  with torch.no_grad():
24
  probs = torch.softmax(self.forward(x), dim=1)
25
  conf, pred = probs.max(dim=1)
26
+ return ['bengali','english'][pred.item()], conf.item()