MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / encode

Method encode

openrec/preprocess/ctc_label_encode.py:68–89  ·  view source on GitHub ↗

convert text-label into text-index. input: text: text labels of each image. [batch_size] output: text: concatenated text index for CTCLoss. [sum(text_lengths)] = [text_index_0 + text_index_1 + ... + text_index_(n - 1)] length:

(self, text)

Source from the content-addressed store, hash-verified

66 return dict_character
67
68 def encode(self, text):
69 """convert text-label into text-index.
70 input:
71 text: text labels of each image. [batch_size]
72
73 output:
74 text: concatenated text index for CTCLoss.
75 [sum(text_lengths)] = [text_index_0 + text_index_1 + ... + text_index_(n - 1)]
76 length: length of each text. [batch_size]
77 """
78 if len(text) == 0:
79 return None
80 if self.lower:
81 text = text.lower()
82 text_list = []
83 for char in text:
84 if char not in self.dict:
85 continue
86 text_list.append(self.dict[char])
87 if len(text_list) == 0 or len(text_list) > self.max_text_len:
88 return None
89 return text_list
90
91
92class CTCLabelEncode(BaseRecLabelEncode):

Callers 1

__call__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected