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)
| 58 | self.character = dict_character |
| 59 | |
| 60 | def encode(self, text): |
| 61 | """convert text-label into text-index. |
| 62 | input: |
| 63 | text: text labels of each image. [batch_size] |
| 64 | |
| 65 | output: |
| 66 | text: concatenated text index for CTCLoss. |
| 67 | [sum(text_lengths)] = [text_index_0 + text_index_1 + ... + text_index_(n - 1)] |
| 68 | length: length of each text. [batch_size] |
| 69 | """ |
| 70 | if self.character_type == "en": |
| 71 | text = text.lower() |
| 72 | |
| 73 | text_list = [] |
| 74 | for char in text: |
| 75 | if char not in self.dict: |
| 76 | continue |
| 77 | text_list.append(self.dict[char]) |
| 78 | text = np.array(text_list) |
| 79 | return text |
| 80 | |
| 81 | def decode(self, text_index, is_remove_duplicate=False): |
| 82 | """ convert text-index into text-label. """ |
no test coverage detected