All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gmm-scale-accs.cc File Reference
Include dependency graph for gmm-scale-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 25 of file gmm-scale-accs.cc.

References kaldi::ConvertStringToReal(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), AccumAmDiagGmm::Read(), ParseOptions::Read(), Vector< Real >::Read(), ParseOptions::Register(), AccumAmDiagGmm::Scale(), VectorBase< Real >::Scale(), Output::Stream(), Input::Stream(), AccumAmDiagGmm::Write(), and VectorBase< Real >::Write().

25  {
26  using namespace kaldi;
27  try {
28  typedef kaldi::int32 int32;
29 
30  const char *usage =
31  "Scale GMM accumulators\n"
32  "Usage: gmm-scale-accs [options] scale stats-in stats-out\n"
33  "e.g.: gmm-scale-accs 0.5 1.stats half.stats\n";
34 
35  bool binary = true;
36  kaldi::ParseOptions po(usage);
37  po.Register("binary", &binary, "Write output in binary mode");
38  po.Read(argc, argv);
39 
40  if (po.NumArgs() != 3) {
41  po.PrintUsage();
42  exit(1);
43  }
44 
45  std::string
46  scale_string = po.GetArg(1),
47  stats_rxfilename = po.GetArg(2),
48  stats_wxfilename = po.GetArg(3);
49 
50  BaseFloat scale;
51  if (!ConvertStringToReal(scale_string, &scale))
52  KALDI_ERR << "Invalid first argument to gmm-scale-accs: expect a number: "
53  << scale_string;
54 
55  kaldi::Vector<double> transition_accs;
56  kaldi::AccumAmDiagGmm gmm_accs;
57 
58  {
59  bool binary_read;
60  kaldi::Input ki(stats_rxfilename, &binary_read);
61  transition_accs.Read(ki.Stream(), binary_read);
62  gmm_accs.Read(ki.Stream(), binary_read);
63  }
64  transition_accs.Scale(scale);
65  gmm_accs.Scale(scale);
66 
67  // Write out the scaled accs.
68  {
69  kaldi::Output ko(stats_wxfilename, binary);
70  transition_accs.Write(ko.Stream(), binary);
71  gmm_accs.Write(ko.Stream(), binary);
72  }
73  KALDI_LOG << "Scaled accs with scale " << scale;
74  } catch(const std::exception &e) {
75  std::cerr << e.what() << '\n';
76  return -1;
77  }
78 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
float BaseFloat
Definition: kaldi-types.h:29
void Write(std::ostream &out_stream, bool binary) const
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Scale(BaseFloat scale)
#define KALDI_ERR
Definition: kaldi-error.h:127
bool ConvertStringToReal(const std::string &str, T *out)
ConvertStringToReal converts a string into either float or double and returns false if there was any ...
Definition: text-utils.cc:238
void Scale(Real alpha)
Multiplies all elements by this constant.
void Read(std::istream &in_stream, bool binary, bool add=false)
#define KALDI_LOG
Definition: kaldi-error.h:133
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.