(label)
| 4 | alp2num_character = None |
| 5 | |
| 6 | def converter(label): |
| 7 | string_label = label |
| 8 | label = [i for i in label] |
| 9 | alp2num = alp2num_character |
| 10 | |
| 11 | batch = len(label) |
| 12 | length = torch.Tensor([len(i) for i in label]).long().cuda() |
| 13 | max_length = max(length) |
| 14 | |
| 15 | text_input = torch.zeros(batch, max_length).long().cuda() |
| 16 | for i in range(batch): |
| 17 | for j in range(len(label[i]) - 1): |
| 18 | text_input[i][j + 1] = alp2num[label[i][j]] |
| 19 | |
| 20 | sum_length = sum(length) |
| 21 | text_all = torch.zeros(sum_length).long().cuda() |
| 22 | start = 0 |
| 23 | for i in range(batch): |
| 24 | for j in range(len(label[i])): |
| 25 | if j == (len(label[i])-1): |
| 26 | text_all[start + j] = alp2num['END'] |
| 27 | else: |
| 28 | text_all[start + j] = alp2num[label[i][j]] |
| 29 | start += len(label[i]) |
| 30 | |
| 31 | |
| 32 | return length, text_input, text_all, None, None, None, string_label |
| 33 | |
| 34 | |
| 35 |
nothing calls this directly
no outgoing calls
no test coverage detected