vector-sum.cc File Reference
#include <vector>
#include <string>
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "matrix/kaldi-vector.h"
#include "transform/transform-common.h"
Include dependency graph for vector-sum.cc:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

int32 TypeOneUsage (const ParseOptions &po)
 
int32 TypeTwoUsage (const ParseOptions &po, bool binary, bool average=false)
 
int32 TypeThreeUsage (const ParseOptions &po, bool binary)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 184 of file vector-sum.cc.

References kaldi::ClassifyRspecifier(), kaldi::ClassifyWspecifier(), ParseOptions::GetArg(), kaldi::kNoRspecifier, kaldi::kNoWspecifier, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), kaldi::TypeOneUsage(), kaldi::TypeThreeUsage(), and kaldi::TypeTwoUsage().

184  {
185  try {
186  using namespace kaldi;
187 
188  const char *usage =
189  "Add vectors (e.g. weights, transition-accs; speaker vectors)\n"
190  "If you need to scale the inputs, use vector-scale on the inputs\n"
191  "\n"
192  "Type one usage:\n"
193  " vector-sum [options] <vector-in-rspecifier1> [<vector-in-rspecifier2>"
194  " <vector-in-rspecifier3> ...] <vector-out-wspecifier>\n"
195  " e.g.: vector-sum ark:1.weights ark:2.weights ark:combine.weights\n"
196  "Type two usage (sums a single table input to produce a single output):\n"
197  " vector-sum [options] <vector-in-rspecifier> <vector-out-wxfilename>\n"
198  " e.g.: vector-sum --binary=false vecs.ark sum.vec\n"
199  "Type three usage (sums single-file inputs to produce a single output):\n"
200  " vector-sum [options] <vector-in-rxfilename1> <vector-in-rxfilename2> ..."
201  " <vector-out-wxfilename>\n"
202  " e.g.: vector-sum --binary=false 1.vec 2.vec 3.vec sum.vec\n"
203  "See also: copy-vector, dot-weights\n";
204 
205  bool binary, average = false;
206 
207  ParseOptions po(usage);
208 
209  po.Register("binary", &binary, "If true, write output as binary (only "
210  "relevant for usage types two or three");
211  po.Register("average", &average, "Do average instead of sum");
212 
213  po.Read(argc, argv);
214 
215  int32 N = po.NumArgs(), exit_status;
216 
217  if (po.NumArgs() >= 2 &&
218  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) != kNoWspecifier) {
219  // output to table.
220  exit_status = TypeOneUsage(po);
221  } else if (po.NumArgs() == 2 &&
222  ClassifyRspecifier(po.GetArg(1), NULL, NULL) != kNoRspecifier &&
223  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) ==
224  kNoWspecifier) {
225  // input from a single table, output not to table.
226  exit_status = TypeTwoUsage(po, binary, average);
227  } else if (po.NumArgs() >= 2 &&
228  ClassifyRspecifier(po.GetArg(1), NULL, NULL) == kNoRspecifier &&
229  ClassifyWspecifier(po.GetArg(N), NULL, NULL, NULL) ==
230  kNoWspecifier) {
231  // summing flat files.
232  exit_status = TypeThreeUsage(po, binary);
233  } else {
234  po.PrintUsage();
235  exit(1);
236  }
237  return exit_status;
238  } catch(const std::exception &e) {
239  std::cerr << e.what();
240  return -1;
241  }
242 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
kaldi::int32 int32
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
int32 TypeTwoUsage(const ParseOptions &po, bool binary)
Definition: matrix-sum.cc:179
int32 TypeOneUsage(const ParseOptions &po, BaseFloat scale1, BaseFloat scale2)
Definition: matrix-sum.cc:30
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
Definition: kaldi-table.cc:135
int32 TypeThreeUsage(const ParseOptions &po, bool binary, bool average)
Definition: matrix-sum.cc:226