From 2c63f3413f7804d497a9a278bc225e2f8a3a92e5 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Fri, 29 Sep 2017 19:55:05 +0800 Subject: [PATCH] convert decoding results to unicode in DS2 --- decoders/swig_wrapper.py | 18 +++++++++++++----- examples/tiny/run_train.sh | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/decoders/swig_wrapper.py b/decoders/swig_wrapper.py index 0a921125..21aed03c 100644 --- a/decoders/swig_wrapper.py +++ b/decoders/swig_wrapper.py @@ -35,7 +35,8 @@ def ctc_greedy_decoder(probs_seq, vocabulary): :return: Decoding result string. :rtype: basestring """ - return swig_decoders.ctc_greedy_decoder(probs_seq.tolist(), vocabulary) + result = swig_decoders.ctc_greedy_decoder(probs_seq.tolist(), vocabulary) + return result.decode('utf-8') def ctc_beam_search_decoder(probs_seq, @@ -69,9 +70,11 @@ def ctc_beam_search_decoder(probs_seq, results, in descending order of the probability. :rtype: list """ - return swig_decoders.ctc_beam_search_decoder(probs_seq.tolist(), vocabulary, - beam_size, cutoff_prob, - cutoff_top_n, ext_scoring_func) + beam_results = swig_decoders.ctc_beam_search_decoder( + probs_seq.tolist(), vocabulary, beam_size, cutoff_prob, cutoff_top_n, + ext_scoring_func) + beam_results = [(res[0], res[1].decode('utf-8')) for res in beam_results] + return beam_results def ctc_beam_search_decoder_batch(probs_split, @@ -111,6 +114,11 @@ def ctc_beam_search_decoder_batch(probs_split, """ probs_split = [probs_seq.tolist() for probs_seq in probs_split] - return swig_decoders.ctc_beam_search_decoder_batch( + batch_beam_results = swig_decoders.ctc_beam_search_decoder_batch( probs_split, vocabulary, beam_size, num_processes, cutoff_prob, cutoff_top_n, ext_scoring_func) + batch_beam_results = [ + [(res[0], res[1].decode("utf-8")) for res in beam_results] + for beam_results in batch_beam_results + ] + return batch_beam_results diff --git a/examples/tiny/run_train.sh b/examples/tiny/run_train.sh index 88b09bee..e03a8aff 100644 --- a/examples/tiny/run_train.sh +++ b/examples/tiny/run_train.sh @@ -33,7 +33,7 @@ python -u train.py \ --shuffle_method='batch_shuffle_clipped' if [ $? -ne 0 ]; then - echo "Fail to do inference!" + echo "Fail in training!" exit 1 fi