|
|
|
@ -19,6 +19,7 @@
|
|
|
|
|
#include "frontend/audio/data_cache.h"
|
|
|
|
|
#include "nnet/decodable.h"
|
|
|
|
|
#include "nnet/ds2_nnet.h"
|
|
|
|
|
#include "decoder/param.h"
|
|
|
|
|
#include "decoder/ctc_tlg_decoder.h"
|
|
|
|
|
|
|
|
|
|
#include "kaldi/util/table-types.h"
|
|
|
|
@ -26,30 +27,7 @@
|
|
|
|
|
|
|
|
|
|
DEFINE_string(feature_rspecifier, "", "test feature rspecifier");
|
|
|
|
|
DEFINE_string(result_wspecifier, "", "test result wspecifier");
|
|
|
|
|
DEFINE_string(model_path, "avg_1.jit.pdmodel", "paddle nnet model");
|
|
|
|
|
DEFINE_string(param_path, "avg_1.jit.pdiparams", "paddle nnet model param");
|
|
|
|
|
DEFINE_string(word_symbol_table, "words.txt", "word symbol table");
|
|
|
|
|
DEFINE_string(graph_path, "TLG", "decoder graph");
|
|
|
|
|
DEFINE_double(acoustic_scale, 1.0, "acoustic scale");
|
|
|
|
|
DEFINE_int32(max_active, 7500, "decoder graph");
|
|
|
|
|
DEFINE_int32(nnet_decoder_chunk, 1, "paddle nnet forward chunk");
|
|
|
|
|
DEFINE_int32(receptive_field_length,
|
|
|
|
|
7,
|
|
|
|
|
"receptive field of two CNN(kernel=3) downsampling module.");
|
|
|
|
|
DEFINE_int32(downsampling_rate,
|
|
|
|
|
4,
|
|
|
|
|
"two CNN(kernel=3) module downsampling rate.");
|
|
|
|
|
DEFINE_string(
|
|
|
|
|
model_input_names,
|
|
|
|
|
"audio_chunk,audio_chunk_lens,chunk_state_h_box,chunk_state_c_box",
|
|
|
|
|
"model input names");
|
|
|
|
|
DEFINE_string(model_output_names,
|
|
|
|
|
"softmax_0.tmp_0,tmp_5,concat_0.tmp_0,concat_1.tmp_0",
|
|
|
|
|
"model output names");
|
|
|
|
|
DEFINE_string(model_cache_names,
|
|
|
|
|
"chunk_state_h_box,chunk_state_c_box",
|
|
|
|
|
"model cache names");
|
|
|
|
|
DEFINE_string(model_cache_shapes, "5-1-1024,5-1-1024", "model cache shapes");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using kaldi::BaseFloat;
|
|
|
|
|
using kaldi::Matrix;
|
|
|
|
@ -66,32 +44,16 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
kaldi::SequentialBaseFloatMatrixReader feature_reader(
|
|
|
|
|
FLAGS_feature_rspecifier);
|
|
|
|
|
kaldi::TokenWriter result_writer(FLAGS_result_wspecifier);
|
|
|
|
|
std::string model_graph = FLAGS_model_path;
|
|
|
|
|
std::string model_params = FLAGS_param_path;
|
|
|
|
|
std::string word_symbol_table = FLAGS_word_symbol_table;
|
|
|
|
|
std::string graph_path = FLAGS_graph_path;
|
|
|
|
|
LOG(INFO) << "model path: " << model_graph;
|
|
|
|
|
LOG(INFO) << "model param: " << model_params;
|
|
|
|
|
LOG(INFO) << "word symbol path: " << word_symbol_table;
|
|
|
|
|
LOG(INFO) << "graph path: " << graph_path;
|
|
|
|
|
|
|
|
|
|
int32 num_done = 0, num_err = 0;
|
|
|
|
|
|
|
|
|
|
ppspeech::TLGDecoderOptions opts;
|
|
|
|
|
opts.word_symbol_table = word_symbol_table;
|
|
|
|
|
opts.fst_path = graph_path;
|
|
|
|
|
opts.opts.max_active = FLAGS_max_active;
|
|
|
|
|
ppspeech::TLGDecoderOptions opts = ppspeech::TLGDecoderOptions::InitFromFlags();
|
|
|
|
|
opts.opts.beam = 15.0;
|
|
|
|
|
opts.opts.lattice_beam = 7.5;
|
|
|
|
|
ppspeech::TLGDecoder decoder(opts);
|
|
|
|
|
|
|
|
|
|
ppspeech::ModelOptions model_opts;
|
|
|
|
|
model_opts.model_path = model_graph;
|
|
|
|
|
model_opts.param_path = model_params;
|
|
|
|
|
model_opts.cache_names = FLAGS_model_cache_names;
|
|
|
|
|
model_opts.cache_shape = FLAGS_model_cache_shapes;
|
|
|
|
|
model_opts.input_names = FLAGS_model_input_names;
|
|
|
|
|
model_opts.output_names = FLAGS_model_output_names;
|
|
|
|
|
ppspeech::ModelOptions model_opts = ppspeech::ModelOptions::InitFromFlags();
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ppspeech::PaddleNnet> nnet(
|
|
|
|
|
new ppspeech::PaddleNnet(model_opts));
|
|
|
|
|
std::shared_ptr<ppspeech::DataCache> raw_data(new ppspeech::DataCache());
|
|
|
|
@ -99,12 +61,13 @@ int main(int argc, char* argv[]) {
|
|
|
|
|
new ppspeech::Decodable(nnet, raw_data, FLAGS_acoustic_scale));
|
|
|
|
|
|
|
|
|
|
int32 chunk_size = FLAGS_receptive_field_length +
|
|
|
|
|
(FLAGS_nnet_decoder_chunk - 1) * FLAGS_downsampling_rate;
|
|
|
|
|
int32 chunk_stride = FLAGS_downsampling_rate * FLAGS_nnet_decoder_chunk;
|
|
|
|
|
(FLAGS_nnet_decoder_chunk - 1) * FLAGS_subsampling_rate;
|
|
|
|
|
int32 chunk_stride = FLAGS_subsampling_rate * FLAGS_nnet_decoder_chunk;
|
|
|
|
|
int32 receptive_field_length = FLAGS_receptive_field_length;
|
|
|
|
|
LOG(INFO) << "chunk size (frame): " << chunk_size;
|
|
|
|
|
LOG(INFO) << "chunk stride (frame): " << chunk_stride;
|
|
|
|
|
LOG(INFO) << "receptive field (frame): " << receptive_field_length;
|
|
|
|
|
|
|
|
|
|
decoder.InitDecoder();
|
|
|
|
|
kaldi::Timer timer;
|
|
|
|
|
for (; !feature_reader.Done(); feature_reader.Next()) {
|
|
|
|
|