nnet-get-feature-transform-multi.cc File Reference
Include dependency graph for nnet-get-feature-transform-multi.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 25 of file nnet-get-feature-transform-multi.cc.

References FeatureTransformEstimateMulti::Estimate(), ParseOptions::GetArg(), rnnlm::i, KALDI_ERR, KALDI_LOG, ParseOptions::NumArgs(), kaldi::PrintableRxfilename(), kaldi::PrintableWxfilename(), ParseOptions::PrintUsage(), LdaEstimate::Read(), ParseOptions::Read(), FeatureTransformEstimateOptions::Register(), ParseOptions::Register(), kaldi::SplitStringToIntegers(), Input::Stream(), and kaldi::WriteKaldiObject().

25  {
26  using namespace kaldi;
27  typedef kaldi::int32 int32;
28  try {
29  const char *usage =
30  "Get feature-projection transform using stats obtained with acc-lda.\n"
31  "The file <index-list> contains a series of line, each containing a list\n"
32  "of integer indexes. For each line we create a transform of the same type\n"
33  "as nnet-get-feature-transform would produce, taking as input just the\n"
34  "listed feature dimensions. The output transform will be the concatenation\n"
35  "of all these transforms. The output-dim will be the number of integers in\n"
36  "the file <index-list> (the individual transforms are not dimension-reducing).\n"
37  "Do not set the --dim option."
38  "Usage: nnet-get-feature-transform-multi [options] <index-list> <lda-acc-1> <lda-acc-2> ... <lda-acc-n> <matrix-out>\n";
39 
40  bool binary = true;
41 
43  ParseOptions po(usage);
44  po.Register("binary", &binary, "Write accumulators in binary mode.");
45  opts.Register(&po);
46  po.Read(argc, argv);
47 
48  if (po.NumArgs() < 2) {
49  po.PrintUsage();
50  exit(1);
51  }
52 
54  std::string index_list_rxfilename = po.GetArg(1);
55  std::string projection_wxfilename = po.GetArg(po.NumArgs());
56 
57  std::vector<std::vector<int32> > indexes;
58  {
59  Input ki(index_list_rxfilename);
60  std::string line;
61  while (getline(ki.Stream(), line)) {
62  std::vector<int32> this_indexes;
63  if (!SplitStringToIntegers(line, " \t\n\r",
64  true, &this_indexes) ||
65  line.empty()) {
66  KALDI_ERR << "Bad line in index-list file: line is " << line;
67  }
68  indexes.push_back(this_indexes);
69  }
70  if (indexes.empty())
71  KALDI_ERR << "Empty index-list file "
72  << PrintableRxfilename(index_list_rxfilename);
73  }
74 
75  for (int32 i = 2; i < po.NumArgs(); i++) {
76  bool binary_in, add = true;
77  Input ki(po.GetArg(i), &binary_in);
78  fte.Read(ki.Stream(), binary_in, add);
79  }
80 
82  fte.Estimate(opts, indexes, &mat);
83  WriteKaldiObject(mat, projection_wxfilename, binary);
84 
85  KALDI_LOG << "Wrote transform to "
86  << PrintableWxfilename(projection_wxfilename);
87  return 0;
88  } catch(const std::exception &e) {
89  std::cerr << e.what();
90  return -1;
91  }
92 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:68
kaldi::int32 int32
void Estimate(const FeatureTransformEstimateOptions &opts, const std::vector< std::vector< int32 > > &indexes, Matrix< BaseFloat > *M) const
This is as FeatureTransformEstimate, but for use in nnet-get-feature-transform-multi.cc, see the usage message of that program for a description of what it does.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Read(std::istream &in_stream, bool binary, bool add)
#define KALDI_ERR
Definition: kaldi-error.h:147
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:61
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:73
#define KALDI_LOG
Definition: kaldi-error.h:153