ivector-extractor-sum-accs.cc
Go to the documentation of this file.
1 // ivectorbin/ivector-extractor-sum-accs.cc
2 
3 // Copyright 2013 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 #include "util/common-utils.h"
22 
23 
24 int main(int argc, char *argv[]) {
25  try {
26  typedef kaldi::int32 int32;
27  using namespace kaldi;
28 
29  const char *usage =
30  "Sum accumulators for training of iVector extractor\n"
31  "Usage: ivector-extractor-sum-accs [options] <stats-in1> "
32  "<stats-in2> ... <stats-inN> <stats-out>\n";
33 
34  bool binary = true;
35  bool parallel = false;
36  kaldi::ParseOptions po(usage);
37  po.Register("binary", &binary, "Write output in binary mode");
38  po.Register("parallel", &parallel, "If true, the program makes sure to "
39  "open all filehandles before reading for any (useful when "
40  "summing accs from long processes)");
41 
42  po.Read(argc, argv);
43 
44  if (po.NumArgs() < 2) {
45  po.PrintUsage();
46  exit(1);
47  }
48 
49  std::string stats_wxfilename = po.GetArg(po.NumArgs());
50 
52 
53  if (parallel) {
54  std::vector<kaldi::Input*> inputs(po.NumArgs() - 1);
55  for (int i = 1; i < po.NumArgs(); i++) {
56  std::string stats_in_filename = po.GetArg(i);
57  inputs[i-1] = new kaldi::Input(stats_in_filename); // Don't try
58  // to work out binary status yet; this would cause us to wait
59  // for the output of that process. We delay it till later.
60  }
61  for (size_t i = 1; i < po.NumArgs(); i++) {
62  bool b;
63  if (kaldi::InitKaldiInputStream(inputs[i-1]->Stream(), &b)) {
64  bool add = true;
65  stats.Read(inputs[i-1]->Stream(), b, add);
66  delete inputs[i-1];
67  } else {
68  KALDI_ERR << "Malformed input file " << po.GetArg(i);
69  }
70  }
71  } else {
72  for (int32 i = 1; i < po.NumArgs(); i++) {
73  std::string stats_rxfilename = po.GetArg(i);
74  KALDI_LOG << "Reading stats from " << stats_rxfilename;
75  bool binary_in;
76  Input ki(stats_rxfilename, &binary_in);
77  bool add = true;
78  stats.Read(ki.Stream(), binary_in, add);
79  }
80  }
81  WriteKaldiObject(stats, stats_wxfilename, binary);
82 
83  KALDI_LOG << "Wrote summed stats to " << stats_wxfilename;
84 
85  return 0;
86  } catch(const std::exception &e) {
87  std::cerr << e.what() << '\n';
88  return -1;
89  }
90 }
91 
92 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
bool InitKaldiInputStream(std::istream &is, bool *binary)
Initialize an opened stream for reading by detecting the binary header and.
Definition: io-funcs-inl.h:306
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
IvectorExtractorStats is a class used to update the parameters of the ivector extractor.
kaldi::int32 int32
void Read(std::istream &is, bool binary, bool add=false)
void Register(const std::string &name, bool *ptr, const std::string &doc)
int main(int argc, char *argv[])
std::istream & Stream()
Definition: kaldi-io.cc:826
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
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 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
#define KALDI_LOG
Definition: kaldi-error.h:153