All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ivector-extractor-sum-accs.cc File Reference
Include dependency graph for ivector-extractor-sum-accs.cc:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 24 of file ivector-extractor-sum-accs.cc.

References ParseOptions::GetArg(), rnnlm::i, kaldi::InitKaldiInputStream(), KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), IvectorExtractorStats::Read(), ParseOptions::Register(), Input::Stream(), and kaldi::WriteKaldiObject().

24  {
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  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  }
68  } else {
69  for (int32 i = 1; i < po.NumArgs(); i++) {
70  std::string stats_rxfilename = po.GetArg(i);
71  KALDI_LOG << "Reading stats from " << stats_rxfilename;
72  bool binary_in;
73  Input ki(stats_rxfilename, &binary_in);
74  bool add = true;
75  stats.Read(ki.Stream(), binary_in, add);
76  }
77  }
78  WriteKaldiObject(stats, stats_wxfilename, binary);
79 
80  KALDI_LOG << "Wrote summed stats to " << stats_wxfilename;
81 
82  return 0;
83  } catch(const std::exception &e) {
84  std::cerr << e.what() << '\n';
85  return -1;
86  }
87 }
Relabels neural network egs with the read pdf-id alignments.
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
IvectorExtractorStats is a class used to update the parameters of the ivector extractor.
void Read(std::istream &is, bool binary, bool add=false)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:133