-
Notifications
You must be signed in to change notification settings - Fork 14
/
test_cctv.py
67 lines (62 loc) · 2.29 KB
/
test_cctv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import paddle.v2 as paddle
import progressbar
import time
from data_utils.data import DataGenerator
from model_utils.model import DeepSpeech2Model
def SpeechRecognizer():
"""Evaluate on whole test data for DeepSpeech2."""
paddle.init(use_gpu=True,
rnn_use_batch=True,
trainer_count=1)
data_generator = DataGenerator(
vocab_filepath='models/aishell/vocab.txt',
mean_std_filepath='models/aishell/mean_std.npz',
augmentation_config='{}',
specgram_type='linear',
num_threads=8,
keep_transcription_text=True)
batch_reader = data_generator.batch_reader_creator(
manifest_path='data/cctv/manifest',
batch_size=128,
min_batch_size=1,
sortagrad=False,
shuffle_method=None)
ds2_model = DeepSpeech2Model(
vocab_size=data_generator.vocab_size,
num_conv_layers=2,
num_rnn_layers=3,
rnn_layer_size=1024,
use_gru=True,
pretrained_model_path='models/aishell/params.tar.gz',
share_rnn_weights=False)
# decoders only accept string encoded in utf-8
vocab_list = [chars.encode("utf-8") for chars in data_generator.vocab_list]
#if args.decoding_method == "ctc_beam_search":
ds2_model.init_ext_scorer(2.6, 5.0, 'models/lm/zh_giga.no_cna_cmn.prune01244.klm',
vocab_list)
ds2_model.logger.info("start evaluation ...")
transcript = []
bar = progressbar.ProgressBar(widgets=[
progressbar.Percentage(),
progressbar.Bar(),
' (', progressbar.SimpleProgress(), ') ',
' (', progressbar.ETA(), ') ', ])
for infer_data in bar(batch_reader()):
probs_split = ds2_model.infer_batch_probs(
infer_data=infer_data,
feeding_dict=data_generator.feeding)
result_transcripts = ds2_model.decode_batch_beam_search(
probs_split=probs_split,
beam_alpha=2.6,
beam_beta=5.0,
beam_size=300,
cutoff_prob=0.99,
cutoff_top_n=40,
vocab_list=vocab_list,
num_processes=8)
transcript += result_transcripts
time.sleep(0.01)
return transcript