fgmm-global-sum-accs.cc
Go to the documentation of this file.
1 // fgmmbin/fgmm-global-sum-accs.cc
2 // Copyright 2009-2011 Saarland University; Microsoft Corporation
3 
4 // See ../../COPYING for clarification regarding multiple authors
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
14 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
15 // MERCHANTABLITY OR NON-INFRINGEMENT.
16 // See the Apache 2 License for the specific language governing permissions and
17 // limitations under the License.
18 
19 #include "util/common-utils.h"
20 #include "gmm/full-gmm.h"
21 #include "gmm/mle-full-gmm.h"
22 
23 
24 int main(int argc, char *argv[]) {
25  try {
26  typedef kaldi::int32 int32;
27 
28  const char *usage =
29  "Sum multiple accumulated stats files for full-covariance GMM "
30  "training.\n"
31  "Usage: fgmm-global-sum-accs [options] stats-out stats-in1 stats-in2 ...\n";
32 
33  bool binary = true;
34  kaldi::ParseOptions po(usage);
35  po.Register("binary", &binary, "Write output in binary mode");
36  po.Read(argc, argv);
37 
38  if (po.NumArgs() < 2) {
39  po.PrintUsage();
40  exit(1);
41  }
42 
43  std::string stats_out_filename = po.GetArg(1);
44  kaldi::AccumFullGmm gmm_accs;
45 
46  for (int i = 2, max = po.NumArgs(); i <= max; i++) {
47  std::string stats_in_filename = po.GetArg(i);
48  bool binary_read;
49  kaldi::Input ki(stats_in_filename, &binary_read);
50  gmm_accs.Read(ki.Stream(), binary_read, true /*add read values*/);
51  }
52 
53  // Write out the accs
54  {
55  kaldi::Output ko(stats_out_filename, binary);
56  gmm_accs.Write(ko.Stream(), binary);
57  }
58 
59  KALDI_LOG << "Written stats to " << stats_out_filename;
60  } catch(const std::exception &e) {
61  std::cerr << e.what() << '\n';
62  return -1;
63  }
64 }
65 
void Write(std::ostream &out_stream, bool binary) const
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
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
std::ostream & Stream()
Definition: kaldi-io.cc:701
int main(int argc, char *argv[])
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
Class for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
Definition: mle-full-gmm.h:74
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void Read(std::istream &in_stream, bool binary, bool add)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_LOG
Definition: kaldi-error.h:153