File tree Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Expand file tree Collapse file tree 1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change 1
1
from __future__ import division
2
2
from __future__ import print_function
3
+ from itertools import groupby
3
4
import numpy as np
4
5
5
6
6
7
def ctcBestPath (mat , classes ):
7
8
"implements best path decoding as shown by Graves (Dissertation, p63)"
8
9
9
- # get list of char indices along best path
10
+ # get char indices along best path
10
11
best_path = np .argmax (mat , axis = 1 )
11
12
12
- # collapse best path and map char indices to string
13
+ # collapse best path (using itertools.groupby), map to chars, join char list to string
13
14
blank_idx = len (classes )
14
- last_char_idx = blank_idx
15
- res = ''
16
- for char_idx in best_path :
17
- if char_idx != last_char_idx and char_idx != blank_idx :
18
- res += classes [char_idx ]
19
- last_char_idx = char_idx
20
-
15
+ best_chars_collapsed = [classes [k ] for k , _ in groupby (best_path ) if k != blank_idx ]
16
+ res = '' .join (best_chars_collapsed )
21
17
return res
22
18
23
19
You can’t perform that action at this time.
0 commit comments