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

◆ main()

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_ERR, 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  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 }
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
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)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
#define KALDI_ERR
Definition: kaldi-error.h:147
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153