gmm-sum-accs.cc File Reference
Include dependency graph for gmm-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 25 of file gmm-sum-accs.cc.

References ParseOptions::GetArg(), rnnlm::i, KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), AccumAmDiagGmm::Read(), ParseOptions::Read(), Vector< Real >::Read(), ParseOptions::Register(), Output::Stream(), Input::Stream(), AccumAmDiagGmm::TotCount(), AccumAmDiagGmm::TotLogLike(), AccumAmDiagGmm::TotStatsCount(), AccumAmDiagGmm::Write(), and VectorBase< Real >::Write().

25  {
26  try {
27  typedef kaldi::int32 int32;
28 
29  const char *usage =
30  "Sum multiple accumulated stats files for GMM training.\n"
31  "Usage: gmm-sum-accs [options] <stats-out> <stats-in1> <stats-in2> ...\n"
32  "E.g.: gmm-sum-accs 1.acc 1.1.acc 1.2.acc\n";
33 
34  bool binary = true;
35  kaldi::ParseOptions po(usage);
36  po.Register("binary", &binary, "Write output in binary mode");
37  po.Read(argc, argv);
38 
39  if (po.NumArgs() < 2) {
40  po.PrintUsage();
41  exit(1);
42  }
43 
44  std::string stats_out_filename = po.GetArg(1);
45  kaldi::Vector<double> transition_accs;
46  kaldi::AccumAmDiagGmm gmm_accs;
47 
48  int num_accs = po.NumArgs() - 1;
49  for (int i = 2, max = po.NumArgs(); i <= max; i++) {
50  std::string stats_in_filename = po.GetArg(i);
51  bool binary_read;
52  kaldi::Input ki(stats_in_filename, &binary_read);
53  transition_accs.Read(ki.Stream(), binary_read, true /*add read values*/);
54  gmm_accs.Read(ki.Stream(), binary_read, true /*add read values*/);
55  }
56 
57  // Write out the accs
58  {
59  kaldi::Output ko(stats_out_filename, binary);
60  transition_accs.Write(ko.Stream(), binary);
61  gmm_accs.Write(ko.Stream(), binary);
62  }
63  KALDI_LOG << "Summed " << num_accs << " stats, total count "
64  << gmm_accs.TotCount() << ", avg like/frame "
65  << (gmm_accs.TotLogLike() / gmm_accs.TotCount());
66  KALDI_LOG << "Total count of stats is " << gmm_accs.TotStatsCount();
67  KALDI_LOG << "Written stats to " << stats_out_filename;
68  } catch(const std::exception &e) {
69  std::cerr << e.what() << '\n';
70  return -1;
71  }
72 }
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
kaldi::int32 int32
BaseFloat TotCount() const
BaseFloat TotLogLike() const
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
BaseFloat TotStatsCount() const
void Read(std::istream &in_stream, bool binary, bool add=false)
void Write(std::ostream &out_stream, bool binary) const
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.