convert text-index into text-label.
(self, text_index, text_prob=None, is_remove_duplicate=False)
| 53 | return dict_character |
| 54 | |
| 55 | def decode(self, text_index, text_prob=None, is_remove_duplicate=False): |
| 56 | """convert text-index into text-label.""" |
| 57 | result_list = [] |
| 58 | ignored_tokens = self.get_ignored_tokens() |
| 59 | batch_size = len(text_index) |
| 60 | for batch_idx in range(batch_size): |
| 61 | selection = np.ones(len(text_index[batch_idx]), dtype=bool) |
| 62 | if is_remove_duplicate: |
| 63 | selection[1:] = text_index[batch_idx][1:] != text_index[ |
| 64 | batch_idx][:-1] |
| 65 | for ignored_token in ignored_tokens: |
| 66 | selection &= text_index[batch_idx] != ignored_token |
| 67 | |
| 68 | char_list = [ |
| 69 | self.character[text_id] |
| 70 | for text_id in text_index[batch_idx][selection] |
| 71 | ] |
| 72 | if text_prob is not None: |
| 73 | conf_list = text_prob[batch_idx][selection] |
| 74 | else: |
| 75 | conf_list = [1] * len(selection) |
| 76 | if len(conf_list) == 0: |
| 77 | conf_list = [0] |
| 78 | |
| 79 | text = ''.join(char_list) |
| 80 | |
| 81 | if self.reverse: # for arabic rec |
| 82 | text = self.pred_reverse(text) |
| 83 | |
| 84 | result_list.append((text, np.mean(conf_list).tolist())) |
| 85 | return result_list |
| 86 | |
| 87 | def get_ignored_tokens(self): |
| 88 | return [0] # for ctc blank |
no test coverage detected