nnet-get-feature-transform-multi.cc
Go to the documentation of this file.
1 // nnet2bin/nnet-get-feature-transform-multi.cc
2 
3 // Copyright 2013 Johns Hopkins University (author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #include "base/kaldi-common.h"
22 #include "util/common-utils.h"
24 
25 int main(int argc, char *argv[]) {
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 }
93 
94 
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
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
kaldi::int32 int32
This file is modified from transform/lda-estimate.h It contains a class intended to be used in precon...
void Register(const std::string &name, bool *ptr, const std::string &doc)
std::istream & Stream()
Definition: kaldi-io.cc:826
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)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
#define KALDI_ERR
Definition: kaldi-error.h:147
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int main(int argc, char *argv[])
int NumArgs() const
Number of positional parameters (c.f. argc-1).
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