35 int main(
int argc,
char *argv[]) {
40 using namespace kaldi;
43 using fst::SymbolTable;
48 "Generate lattices using nnet3 neural net model. This version supports\n" 49 "multiple decoding threads (using a shared decoding graph.)\n" 50 "Usage: nnet3-latgen-faster-parallel [options] <nnet-in> <fst-in|fsts-rspecifier> <features-rspecifier>" 51 " <lattice-wspecifier> [ <words-wspecifier> [<alignments-wspecifier>] ]\n" 52 "See also: nnet3-latgen-faster-batch (which supports GPUs)\n";
56 bool allow_partial =
false;
61 std::string word_syms_filename;
62 std::string ivector_rspecifier,
63 online_ivector_rspecifier,
65 int32 online_ivector_period = 0;
69 po.
Register(
"word-symbol-table", &word_syms_filename,
70 "Symbol table for words [for debug output]");
71 po.
Register(
"allow-partial", &allow_partial,
72 "If true, produce output even if end state was not reached.");
73 po.
Register(
"ivectors", &ivector_rspecifier,
"Rspecifier for " 74 "iVectors as vectors (i.e. not estimated online); per utterance " 75 "by default, or per speaker if you provide the --utt2spk option.");
76 po.
Register(
"online-ivectors", &online_ivector_rspecifier,
"Rspecifier for " 77 "iVectors estimated online, as matrices. If you supply this," 78 " you must set the --online-ivector-period option.");
79 po.
Register(
"online-ivector-period", &online_ivector_period,
"Number of frames " 80 "between iVectors in matrices supplied to the --online-ivectors " 90 std::string model_in_filename = po.
GetArg(1),
92 feature_rspecifier = po.
GetArg(3),
93 lattice_wspecifier = po.
GetArg(4),
102 Input ki(model_in_filename, &binary);
113 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
114 : lattice_writer.
Open(lattice_wspecifier)))
115 KALDI_ERR <<
"Could not open table for writing lattices: " 116 << lattice_wspecifier;
119 online_ivector_rspecifier);
121 ivector_rspecifier, utt2spk_rspecifier);
126 fst::SymbolTable *word_syms = NULL;
127 if (word_syms_filename !=
"")
128 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
129 KALDI_ERR <<
"Could not read symbol table from file " 130 << word_syms_filename;
132 double tot_like = 0.0;
133 kaldi::int64 frame_count = 0;
134 int num_success = 0, num_fail = 0;
144 for (; !feature_reader.
Done(); feature_reader.
Next()) {
145 std::string utt = feature_reader.
Key();
147 if (features.NumRows() == 0) {
148 KALDI_WARN <<
"Zero-length utterance: " << utt;
154 if (!ivector_rspecifier.empty()) {
155 if (!ivector_reader.
HasKey(utt)) {
156 KALDI_WARN <<
"No iVector available for utterance " << utt;
160 ivector = &ivector_reader.
Value(utt);
163 if (!online_ivector_rspecifier.empty()) {
164 if (!online_ivector_reader.
HasKey(utt)) {
165 KALDI_WARN <<
"No online iVector available for utterance " << utt;
169 online_ivectors = &online_ivector_reader.
Value(utt);
178 decodable_opts, trans_model, am_nnet,
179 features, ivector, online_ivectors,
180 online_ivector_period);
184 decoder, nnet_decodable,
186 determinize, allow_partial, &alignment_writer, &words_writer,
187 &compact_lattice_writer, &lattice_writer,
188 &tot_like, &frame_count, &num_success, &num_fail, NULL);
199 for (; !fst_reader.
Done(); fst_reader.
Next()) {
200 std::string utt = fst_reader.
Key();
201 if (!feature_reader.
HasKey(utt)) {
202 KALDI_WARN <<
"Not decoding utterance " << utt
203 <<
" because no features available.";
209 KALDI_WARN <<
"Zero-length utterance: " << utt;
216 if (!ivector_rspecifier.empty()) {
217 if (!ivector_reader.
HasKey(utt)) {
218 KALDI_WARN <<
"No iVector available for utterance " << utt;
222 ivector = &ivector_reader.
Value(utt);
225 if (!online_ivector_rspecifier.empty()) {
226 if (!online_ivector_reader.
HasKey(utt)) {
227 KALDI_WARN <<
"No online iVector available for utterance " << utt;
231 online_ivectors = &online_ivector_reader.
Value(utt);
242 decodable_opts, trans_model, am_nnet,
243 features, ivector, online_ivectors,
244 online_ivector_period);
248 decoder, nnet_decodable,
250 determinize, allow_partial, &alignment_writer, &words_writer,
251 &compact_lattice_writer, &lattice_writer,
252 &tot_like, &frame_count, &num_success, &num_fail, NULL);
260 kaldi::int64 input_frame_count =
263 double elapsed = timer.
Elapsed();
265 <<
"s: real-time factor assuming 100 feature frames/sec is " 266 << (sequencer_config.
num_threads * elapsed * 100.0 /
268 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 270 KALDI_LOG <<
"Overall log-likelihood per frame is " 271 << (tot_like / frame_count) <<
" over " 272 << frame_count <<
" frames.";
275 if (num_success != 0)
return 0;
277 }
catch(
const std::exception &e) {
278 std::cerr << e.what();
int main(int argc, char *argv[])
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void CollapseModel(const CollapseModelConfig &config, Nnet *nnet)
This function modifies the neural net for efficiency, in a way that suitable to be done in test time...
bool Open(const std::string &wspecifier)
DecodableInterface provides a link between the (acoustic-modeling and feature-processing) code and th...
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
void Run(C *c)
This function takes ownership of the pointer "c", and will delete it in the same sequence as Run was ...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
This class is for when you are reading something in random access, but it may actually be stored per-...
void SetBatchnormTestMode(bool test_mode, Nnet *nnet)
This function affects only components of type BatchNormComponent.
A templated class for writing objects to an archive or script file; see The Table concept...
const Nnet & GetNnet() const
void Read(std::istream &is, bool binary)
void Register(const std::string &name, bool *ptr, const std::string &doc)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
This file contains some miscellaneous functions dealing with class Nnet.
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void SetDropoutTestMode(bool test_mode, Nnet *nnet)
This function affects components of child-classes of RandomComponent.
This class basically does the same job as the function DecodeUtteranceLatticeFaster, but in a way that allows us to build a multi-threaded command line program more easily.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
void Read(std::istream &is, bool binary)
void Register(OptionsItf *opts)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
bool HasKey(const std::string &key)
This is the "normal" lattice-generating decoder.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
LatticeFasterDecoderTpl< fst::StdFst, decoder::StdToken > LatticeFasterDecoder
const T & Value(const std::string &key)
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
int32 frame_subsampling_factor
std::string GetOptArg(int param) const
void Register(OptionsItf *opts)
Config class for the CollapseModel function.