|
|
@ -27,14 +27,20 @@ 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(param_path, "avg_1.jit.pdiparams", "paddle nnet model param");
|
|
|
|
DEFINE_string(word_symbol_table, "vocab.txt", "word symbol table");
|
|
|
|
DEFINE_string(word_symbol_table, "vocab.txt", "word symbol table");
|
|
|
|
DEFINE_string(graph_path, "TLG", "decoder graph");
|
|
|
|
DEFINE_string(graph_path, "TLG", "decoder graph");
|
|
|
|
DEFINE_double(acoustic_scale, 10.0, "acoustic scale");
|
|
|
|
DEFINE_double(acoustic_scale, 1.0, "acoustic scale");
|
|
|
|
DEFINE_int32(max_active, 5000, "decoder graph");
|
|
|
|
DEFINE_int32(max_active, 7500, "decoder graph");
|
|
|
|
|
|
|
|
DEFINE_int32(receptive_field_length,
|
|
|
|
|
|
|
|
7,
|
|
|
|
|
|
|
|
"receptive field of two CNN(kernel=5) downsampling module.");
|
|
|
|
|
|
|
|
DEFINE_int32(downsampling_rate,
|
|
|
|
|
|
|
|
4,
|
|
|
|
|
|
|
|
"two CNN(kernel=5) module downsampling rate.");
|
|
|
|
|
|
|
|
|
|
|
|
using kaldi::BaseFloat;
|
|
|
|
using kaldi::BaseFloat;
|
|
|
|
using kaldi::Matrix;
|
|
|
|
using kaldi::Matrix;
|
|
|
|
using std::vector;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// test clg decoder by feeding speech feature.
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, false);
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, false);
|
|
|
|
google::InitGoogleLogging(argv[0]);
|
|
|
|
google::InitGoogleLogging(argv[0]);
|
|
|
@ -52,7 +58,8 @@ int main(int argc, char* argv[]) {
|
|
|
|
opts.word_symbol_table = word_symbol_table;
|
|
|
|
opts.word_symbol_table = word_symbol_table;
|
|
|
|
opts.fst_path = graph_path;
|
|
|
|
opts.fst_path = graph_path;
|
|
|
|
opts.opts.max_active = FLAGS_max_active;
|
|
|
|
opts.opts.max_active = FLAGS_max_active;
|
|
|
|
opts.opts.beam =
|
|
|
|
opts.opts.beam = 15.0;
|
|
|
|
|
|
|
|
opts.opts.lattice_beam = 7.5;
|
|
|
|
ppspeech::TLGDecoder decoder(opts);
|
|
|
|
ppspeech::TLGDecoder decoder(opts);
|
|
|
|
|
|
|
|
|
|
|
|
ppspeech::ModelOptions model_opts;
|
|
|
|
ppspeech::ModelOptions model_opts;
|
|
|
@ -61,30 +68,55 @@ int main(int argc, char* argv[]) {
|
|
|
|
model_opts.cache_shape = "5-1-1024,5-1-1024";
|
|
|
|
model_opts.cache_shape = "5-1-1024,5-1-1024";
|
|
|
|
std::shared_ptr<ppspeech::PaddleNnet> nnet(
|
|
|
|
std::shared_ptr<ppspeech::PaddleNnet> nnet(
|
|
|
|
new ppspeech::PaddleNnet(model_opts));
|
|
|
|
new ppspeech::PaddleNnet(model_opts));
|
|
|
|
std::shared_ptr<ppspeech::DataCache> raw_data(
|
|
|
|
std::shared_ptr<ppspeech::DataCache> raw_data(new ppspeech::DataCache());
|
|
|
|
new ppspeech::DataCache());
|
|
|
|
|
|
|
|
std::shared_ptr<ppspeech::Decodable> decodable(
|
|
|
|
std::shared_ptr<ppspeech::Decodable> decodable(
|
|
|
|
new ppspeech::Decodable(nnet, raw_data));
|
|
|
|
new ppspeech::Decodable(nnet, raw_data, FLAGS_acoustic_scale));
|
|
|
|
|
|
|
|
|
|
|
|
int32 chunk_size = 35;
|
|
|
|
int32 chunk_size = FLAGS_receptive_field_length;
|
|
|
|
|
|
|
|
int32 chunk_stride = FLAGS_downsampling_rate;
|
|
|
|
|
|
|
|
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();
|
|
|
|
decoder.InitDecoder();
|
|
|
|
|
|
|
|
|
|
|
|
for (; !feature_reader.Done(); feature_reader.Next()) {
|
|
|
|
for (; !feature_reader.Done(); feature_reader.Next()) {
|
|
|
|
string utt = feature_reader.Key();
|
|
|
|
string utt = feature_reader.Key();
|
|
|
|
const kaldi::Matrix<BaseFloat> feature = feature_reader.Value();
|
|
|
|
kaldi::Matrix<BaseFloat> feature = feature_reader.Value();
|
|
|
|
raw_data->SetDim(feature.NumCols());
|
|
|
|
raw_data->SetDim(feature.NumCols());
|
|
|
|
|
|
|
|
LOG(INFO) << "process utt: " << utt;
|
|
|
|
|
|
|
|
LOG(INFO) << "rows: " << feature.NumRows();
|
|
|
|
|
|
|
|
LOG(INFO) << "cols: " << feature.NumCols();
|
|
|
|
|
|
|
|
|
|
|
|
int32 row_idx = 0;
|
|
|
|
int32 row_idx = 0;
|
|
|
|
int32 num_chunks = feature.NumRows() / chunk_size;
|
|
|
|
int32 padding_len = 0;
|
|
|
|
|
|
|
|
int32 ori_feature_len = feature.NumRows();
|
|
|
|
|
|
|
|
if ((feature.NumRows() - chunk_size) % chunk_stride != 0) {
|
|
|
|
|
|
|
|
padding_len =
|
|
|
|
|
|
|
|
chunk_stride - (feature.NumRows() - chunk_size) % chunk_stride;
|
|
|
|
|
|
|
|
feature.Resize(feature.NumRows() + padding_len,
|
|
|
|
|
|
|
|
feature.NumCols(),
|
|
|
|
|
|
|
|
kaldi::kCopyData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 num_chunks = (feature.NumRows() - chunk_size) / chunk_stride + 1;
|
|
|
|
for (int chunk_idx = 0; chunk_idx < num_chunks; ++chunk_idx) {
|
|
|
|
for (int chunk_idx = 0; chunk_idx < num_chunks; ++chunk_idx) {
|
|
|
|
kaldi::Vector<kaldi::BaseFloat> feature_chunk(chunk_size *
|
|
|
|
kaldi::Vector<kaldi::BaseFloat> feature_chunk(chunk_size *
|
|
|
|
feature.NumCols());
|
|
|
|
feature.NumCols());
|
|
|
|
|
|
|
|
int32 feature_chunk_size = 0;
|
|
|
|
|
|
|
|
if (ori_feature_len > chunk_idx * chunk_stride) {
|
|
|
|
|
|
|
|
feature_chunk_size = std::min(
|
|
|
|
|
|
|
|
ori_feature_len - chunk_idx * chunk_stride, chunk_size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (feature_chunk_size < receptive_field_length) break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32 start = chunk_idx * chunk_stride;
|
|
|
|
for (int row_id = 0; row_id < chunk_size; ++row_id) {
|
|
|
|
for (int row_id = 0; row_id < chunk_size; ++row_id) {
|
|
|
|
kaldi::SubVector<kaldi::BaseFloat> tmp(feature, row_idx);
|
|
|
|
kaldi::SubVector<kaldi::BaseFloat> tmp(feature, start);
|
|
|
|
kaldi::SubVector<kaldi::BaseFloat> f_chunk_tmp(
|
|
|
|
kaldi::SubVector<kaldi::BaseFloat> f_chunk_tmp(
|
|
|
|
feature_chunk.Data() + row_id * feature.NumCols(),
|
|
|
|
feature_chunk.Data() + row_id * feature.NumCols(),
|
|
|
|
feature.NumCols());
|
|
|
|
feature.NumCols());
|
|
|
|
f_chunk_tmp.CopyFromVec(tmp);
|
|
|
|
f_chunk_tmp.CopyFromVec(tmp);
|
|
|
|
row_idx++;
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
raw_data->Accept(feature_chunk);
|
|
|
|
raw_data->Accept(feature_chunk);
|
|
|
|
if (chunk_idx == num_chunks - 1) {
|
|
|
|
if (chunk_idx == num_chunks - 1) {
|
|
|
|