Skip to content

Commit c7fb302

Browse files
committed
add telugu support
1 parent e387d65 commit c7fb302

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

easyocr/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'ava','dar','inh','che','lbe','lez','tab']
2222
devanagari_lang_list = ['hi','mr','ne','bh','mai','ang','bho','mah','sck','new',\
2323
'gom','sa','bgc']
24-
other_lang_list = ['th','ch_sim','ch_tra','ja','ko','ta']
24+
other_lang_list = ['th','ch_sim','ch_tra','ja','ko','ta','te','kn']
2525

2626
all_lang_list = latin_lang_list + arabic_lang_list+ cyrillic_lang_list +\
2727
devanagari_lang_list + bengali_lang_list + other_lang_list
@@ -48,6 +48,7 @@
4848
'bn_char' : '।ঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ািীুূৃেৈোৌ্ৎড়ঢ়য়০১২৩৪৫৬৭৮৯',
4949
'th_char' : 'กขคฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮฤ' +'เแโใไะา'+ special_c + 'ํฺ'+'ฯๆ',
5050
'th_number' : '0123456789๑๒๓๔๕๖๗๘๙',
51+
'te_char': 'ఁంఃఅఆఇఈఉఊఋఌఎఏఐఒఓఔకఖగఘఙచఛజఝఞటఠడఢణతథదధనపఫబభమయరఱలళవశషసహాిీుూృౄెేైొోౌ్ౠౡౢౣ',
5152
}
5253

5354
# first element is url path, second is file size
@@ -64,4 +65,6 @@
6465
'arabic.pth': ('https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/arabic.zip', '993074555550e4e06a6077d55ff0449a'),
6566
'tamil.pth': ('https://github.com/JaidedAI/EasyOCR/releases/download/v1.1.7/tamil.zip', '4b93972fdacdcdabe6d57097025d4dc2'),
6667
'bengali.pth': ('https://github.com/JaidedAI/EasyOCR/releases/download/v1.1.8/bengali.zip', 'cea9e897e2c0576b62cbb1554997ce1c'),
68+
'telugu.pth': ('https://github.com/JaidedAI/EasyOCR/releases/download/v1.1.11/telugu.zip', 'f7576012a3abe593950c47bfa1bd8ddc'),
69+
'kannada.pth': ('https://github.com/JaidedAI/EasyOCR/releases/download/v1.1.11/kannada.zip', ''),
6770
}

easyocr/easyocr.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def __init__(self, lang_list, gpu=True, model_storage_directory=None,
125125
self.setModelLanguage('korean', lang_list, ['ko','en'], '["ko","en"]')
126126
elif 'ta' in lang_list:
127127
self.setModelLanguage('tamil', lang_list, ['ta','en'], '["ta","en"]')
128+
elif 'te' in lang_list:
129+
self.setModelLanguage('telugu', lang_list, ['te','en'], '["te","en"]')
128130
elif set(lang_list) & set(bengali_lang_list):
129131
self.setModelLanguage('bengali', lang_list, bengali_lang_list+['en'], '["bn","as","en"]')
130132
elif set(lang_list) & set(arabic_lang_list):
@@ -171,6 +173,10 @@ def __init__(self, lang_list, gpu=True, model_storage_directory=None,
171173
ta_char = self.getChar("ta_char.txt")
172174
self.character = number + symbol + characters['en_char'] + ta_char
173175
model_file = 'tamil.pth'
176+
elif self.model_lang == 'telugu':
177+
self.character = number + symbol + characters['en_char'] + characters['te_char']
178+
model_file = 'telugu.pth'
179+
recog_network = 'lite'
174180
elif self.model_lang == 'thai':
175181
separator_list = {
176182
'th': ['\xa2', '\xa3'],
@@ -227,6 +233,12 @@ def __init__(self, lang_list, gpu=True, model_storage_directory=None,
227233
'output_channel': 512,
228234
'hidden_size': 512
229235
}
236+
elif recog_network == 'lite':
237+
network_params = {
238+
'input_channel': 1,
239+
'output_channel': 256,
240+
'hidden_size': 256
241+
}
230242
else:
231243
network_params = recog_config['network_params']
232244
self.recognizer, self.converter = get_recognizer(recog_network, network_params,\

easyocr/model/modules.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ def forward(self, input):
8989
output = self.linear(recurrent) # batch_size x T x output_size
9090
return output
9191

92+
class VGG_FeatureExtractor(nn.Module):
93+
94+
def __init__(self, input_channel, output_channel=256):
95+
super(VGG_FeatureExtractor, self).__init__()
96+
self.output_channel = [int(output_channel / 8), int(output_channel / 4),
97+
int(output_channel / 2), output_channel]
98+
self.ConvNet = nn.Sequential(
99+
nn.Conv2d(input_channel, self.output_channel[0], 3, 1, 1), nn.ReLU(True),
100+
nn.MaxPool2d(2, 2),
101+
nn.Conv2d(self.output_channel[0], self.output_channel[1], 3, 1, 1), nn.ReLU(True),
102+
nn.MaxPool2d(2, 2),
103+
nn.Conv2d(self.output_channel[1], self.output_channel[2], 3, 1, 1), nn.ReLU(True),
104+
nn.Conv2d(self.output_channel[2], self.output_channel[2], 3, 1, 1), nn.ReLU(True),
105+
nn.MaxPool2d((2, 1), (2, 1)),
106+
nn.Conv2d(self.output_channel[2], self.output_channel[3], 3, 1, 1, bias=False),
107+
nn.BatchNorm2d(self.output_channel[3]), nn.ReLU(True),
108+
nn.Conv2d(self.output_channel[3], self.output_channel[3], 3, 1, 1, bias=False),
109+
nn.BatchNorm2d(self.output_channel[3]), nn.ReLU(True),
110+
nn.MaxPool2d((2, 1), (2, 1)),
111+
nn.Conv2d(self.output_channel[3], self.output_channel[3], 2, 1, 0), nn.ReLU(True))
112+
113+
def forward(self, input):
114+
return self.ConvNet(input)
115+
92116
class ResNet_FeatureExtractor(nn.Module):
93117
""" FeatureExtractor of FAN (http://openaccess.thecvf.com/content_ICCV_2017/papers/Cheng_Focusing_Attention_Towards_ICCV_2017_paper.pdf) """
94118

easyocr/model/vgg_model.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import torch.nn as nn
2+
from .modules import VGG_FeatureExtractor, BidirectionalLSTM
3+
4+
class Model(nn.Module):
5+
6+
def __init__(self, input_channel, output_channel, hidden_size, num_class):
7+
super(Model, self).__init__()
8+
""" FeatureExtraction """
9+
self.FeatureExtraction = VGG_FeatureExtractor(input_channel, output_channel)
10+
self.FeatureExtraction_output = output_channel
11+
self.AdaptiveAvgPool = nn.AdaptiveAvgPool2d((None, 1))
12+
13+
""" Sequence modeling"""
14+
self.SequenceModeling = nn.Sequential(
15+
BidirectionalLSTM(self.FeatureExtraction_output, hidden_size, hidden_size),
16+
BidirectionalLSTM(hidden_size, hidden_size, hidden_size))
17+
self.SequenceModeling_output = hidden_size
18+
19+
""" Prediction """
20+
self.Prediction = nn.Linear(self.SequenceModeling_output, num_class)
21+
22+
23+
def forward(self, input, text):
24+
""" Feature extraction stage """
25+
visual_feature = self.FeatureExtraction(input)
26+
visual_feature = self.AdaptiveAvgPool(visual_feature.permute(0, 3, 1, 2))
27+
visual_feature = visual_feature.squeeze(3)
28+
29+
""" Sequence modeling stage """
30+
contextual_feature = self.SequenceModeling(visual_feature)
31+
32+
""" Prediction stage """
33+
prediction = self.Prediction(contextual_feature.contiguous())
34+
35+
return prediction

easyocr/recognition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def get_recognizer(recog_network, network_params, character,\
147147

148148
if recog_network == 'standard':
149149
model_pkg = importlib.import_module("easyocr.model.model")
150+
elif recog_network == 'lite':
151+
model_pkg = importlib.import_module("easyocr.model.vgg_model")
150152
else:
151153
model_pkg = importlib.import_module(recog_network)
152154
model = model_pkg.Model(num_class=num_class, **network_params)

0 commit comments

Comments
 (0)