I am following the CRNN implementation of https://github.com/meijieru/crnn.pytorch, but seems like it is not using beam search for decoding the words. Can someone tell me how to add beam search decoding in the same model? At the same time in Tensorflow, there is an inbuilt tf.nn.ctc_beam_search_decoder
.
i know its not a great idea, but i did it using tensorflow inside pytorch.
if(beam):
decodes, _ = tf.nn.ctc_beam_search_decoder(inputs=preds_.cpu().detach().numpy(),
sequence_length=25*np.ones(1), merge_repeated=False)
with tf.Session(config = tf.ConfigProto(device_count = {'GPU': 0})) as sess:
t_ = sess.run(decodes)[0].values
char_list = []
for i in range(len(sess.run(decodes)[0].values)):
if t_[i] != 0 and (not (i > 0 and t_[i - 1] == t_[i])):
char_list.append(alphabet[t_[i] - 1])
sim_pred = ''.join(char_list)
else:
raw_pred = converter.decode(preds.data, preds_size.data, raw=True)
sim_pred = converter.decode(preds.data, preds_size.data, raw=False)