Update default config params and result display for evaluator.py and infer.py for DS2.

pull/2/head
Xinghai Sun 8 years ago
parent de212572ed
commit 92eacf548b

@ -4,6 +4,7 @@ from __future__ import division
from __future__ import print_function from __future__ import print_function
import distutils.util import distutils.util
import sys
import argparse import argparse
import gzip import gzip
import paddle.v2 as paddle import paddle.v2 as paddle
@ -12,13 +13,19 @@ from model import deep_speech2
from decoder import * from decoder import *
from lm.lm_scorer import LmScorer from lm.lm_scorer import LmScorer
from error_rate import wer from error_rate import wer
import utils
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument( parser.add_argument(
"--batch_size", "--batch_size",
default=100, default=128,
type=int, type=int,
help="Minibatch size for evaluation. (default: %(default)s)") help="Minibatch size for evaluation. (default: %(default)s)")
parser.add_argument(
"--trainer_count",
default=8,
type=int,
help="Trainer number. (default: %(default)s)")
parser.add_argument( parser.add_argument(
"--num_conv_layers", "--num_conv_layers",
default=2, default=2,
@ -58,8 +65,8 @@ parser.add_argument(
"--decode_method", "--decode_method",
default='beam_search', default='beam_search',
type=str, type=str,
help="Method for ctc decoding, best_path or beam_search. (default: %(default)s)" help="Method for ctc decoding, best_path or beam_search. "
) "(default: %(default)s)")
parser.add_argument( parser.add_argument(
"--language_model_path", "--language_model_path",
default="lm/data/common_crawl_00.prune01111.trie.klm", default="lm/data/common_crawl_00.prune01111.trie.klm",
@ -67,12 +74,12 @@ parser.add_argument(
help="Path for language model. (default: %(default)s)") help="Path for language model. (default: %(default)s)")
parser.add_argument( parser.add_argument(
"--alpha", "--alpha",
default=0.26, default=0.36,
type=float, type=float,
help="Parameter associated with language model. (default: %(default)f)") help="Parameter associated with language model. (default: %(default)f)")
parser.add_argument( parser.add_argument(
"--beta", "--beta",
default=0.1, default=0.25,
type=float, type=float,
help="Parameter associated with word count. (default: %(default)f)") help="Parameter associated with word count. (default: %(default)f)")
parser.add_argument( parser.add_argument(
@ -191,7 +198,7 @@ def evaluate():
blank_id=len(data_generator.vocab_list), blank_id=len(data_generator.vocab_list),
num_processes=args.num_processes_beam_search, num_processes=args.num_processes_beam_search,
ext_scoring_func=ext_scorer, ext_scoring_func=ext_scorer,
cutoff_prob=args.cutoff_prob, ) cutoff_prob=args.cutoff_prob)
for i, beam_search_result in enumerate(beam_search_results): for i, beam_search_result in enumerate(beam_search_results):
wer_sum += wer(target_transcription[i], wer_sum += wer(target_transcription[i],
beam_search_result[0][1]) beam_search_result[0][1])
@ -199,12 +206,15 @@ def evaluate():
else: else:
raise ValueError("Decoding method [%s] is not supported." % raise ValueError("Decoding method [%s] is not supported." %
decode_method) decode_method)
print("WER (%d/?) = %f" % (wer_counter, wer_sum / wer_counter))
print("Final WER = %f" % (wer_sum / wer_counter)) print("Final WER (%d/%d) = %f" % (wer_counter, wer_counter,
wer_sum / wer_counter))
def main(): def main():
paddle.init(use_gpu=args.use_gpu, trainer_count=1) utils.print_arguments(args)
paddle.init(use_gpu=args.use_gpu, trainer_count=args.trainer_count)
evaluate() evaluate()

@ -57,6 +57,11 @@ parser.add_argument(
type=str, type=str,
help="Feature type of audio data: 'linear' (power spectrum)" help="Feature type of audio data: 'linear' (power spectrum)"
" or 'mfcc'. (default: %(default)s)") " or 'mfcc'. (default: %(default)s)")
parser.add_argument(
"--trainer_count",
default=8,
type=int,
help="Trainer number. (default: %(default)s)")
parser.add_argument( parser.add_argument(
"--mean_std_filepath", "--mean_std_filepath",
default='mean_std.npz', default='mean_std.npz',
@ -208,7 +213,7 @@ def infer():
wer_cur = wer(target_transcription[i], beam_search_result[0][1]) wer_cur = wer(target_transcription[i], beam_search_result[0][1])
wer_sum += wer_cur wer_sum += wer_cur
wer_counter += 1 wer_counter += 1
print("cur wer = %f , average wer = %f" % print("Current WER = %f , Average WER = %f" %
(wer_cur, wer_sum / wer_counter)) (wer_cur, wer_sum / wer_counter))
else: else:
raise ValueError("Decoding method [%s] is not supported." % raise ValueError("Decoding method [%s] is not supported." %
@ -217,7 +222,7 @@ def infer():
def main(): def main():
utils.print_arguments(args) utils.print_arguments(args)
paddle.init(use_gpu=args.use_gpu, trainer_count=1) paddle.init(use_gpu=args.use_gpu, trainer_count=args.trainer_count)
infer() infer()

Loading…
Cancel
Save