sgmm2-comp-prexform.cc File Reference
Include dependency graph for sgmm2-comp-prexform.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 26 of file sgmm2-comp-prexform.cc.

References AmSgmm2::ComputeFmllrPreXform(), ParseOptions::GetArg(), Sgmm2FmllrGlobalParams::inv_xform_, KALDI_LOG, kaldi::kSgmmWriteAll, Sgmm2FmllrGlobalParams::mean_scatter_, ParseOptions::NumArgs(), Sgmm2FmllrGlobalParams::pre_xform_, ParseOptions::PrintUsage(), ParseOptions::Read(), TransitionModel::Read(), AmSgmm2::Read(), Vector< Real >::Read(), ParseOptions::Register(), Output::Stream(), Input::Stream(), Sgmm2FmllrGlobalParams::Write(), TransitionModel::Write(), and AmSgmm2::Write().

26  {
27  try {
28  typedef kaldi::int32 int32;
29 
30  const char *usage =
31  "Compute \"pre-transform\" parameters required for estimating fMLLR with\n"
32  "SGMMs, and write to a model file, after the SGMM.\n"
33  "Usage: sgmm2-comp-prexform [options] <sgmm2-in> <occs-in> <sgmm-out>\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 sgmm_in_filename = po.GetArg(1),
46  occs_filename = po.GetArg(2),
47  sgmm_out_filename = po.GetArg(3);
48 
49  kaldi::AmSgmm2 sgmm_in;
50  kaldi::TransitionModel trans_model;
51  {
52  bool binary_read;
53  kaldi::Input ki(sgmm_in_filename, &binary_read);
54  trans_model.Read(ki.Stream(), binary_read);
55  sgmm_in.Read(ki.Stream(), binary_read);
56  }
57 
59  {
60  bool binary_read;
61  kaldi::Input ki(occs_filename, &binary_read);
62  occs.Read(ki.Stream(), binary_read);
63  }
64 
65  kaldi::Sgmm2FmllrGlobalParams fmllr_globals;
66  sgmm_in.ComputeFmllrPreXform(occs, &fmllr_globals.pre_xform_,
67  &fmllr_globals.inv_xform_,
68  &fmllr_globals.mean_scatter_);
69 
70  {
71  kaldi::Output ko(sgmm_out_filename, binary);
72  trans_model.Write(ko.Stream(), binary);
73  sgmm_in.Write(ko.Stream(), binary, kaldi::kSgmmWriteAll);
74  fmllr_globals.Write(ko.Stream(), binary);
75  }
76 
77  KALDI_LOG << "Written model to " << sgmm_out_filename;
78  } catch(const std::exception &e) {
79  std::cerr << e.what() << '\n';
80  return -1;
81  }
82 }
void Write(std::ostream &os, bool binary, SgmmWriteFlagsType write_params) const
Definition: am-sgmm2.cc:203
Class for definition of the subspace Gmm acoustic model.
Definition: am-sgmm2.h:231
void Write(std::ostream &out_stream, bool binary) const
Definition: fmllr-sgmm2.cc:103
Matrix< BaseFloat > pre_xform_
Pre-transform matrix. Dim is [D][D+1].
Definition: fmllr-sgmm2.h:103
void Read(std::istream &is, bool binary)
Definition: am-sgmm2.cc:89
kaldi::int32 int32
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
Matrix< BaseFloat > inv_xform_
Inverse of pre-transform. Dim is [D][D+1].
Definition: fmllr-sgmm2.h:105
void Read(std::istream &is, bool binary)
void Write(std::ostream &os, bool binary) const
A class representing a vector.
Definition: kaldi-vector.h:406
Global adaptation parameters.
Definition: fmllr-sgmm2.h:91
Vector< BaseFloat > mean_scatter_
Diagonal of mean-scatter matrix. Dim is [D].
Definition: fmllr-sgmm2.h:107
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.
void ComputeFmllrPreXform(const Vector< BaseFloat > &pdf_occs, Matrix< BaseFloat > *xform, Matrix< BaseFloat > *inv_xform, Vector< BaseFloat > *diag_mean_scatter) const
Computes the LDA-like pre-transform and its inverse as well as the eigenvalues of the scatter of the ...
Definition: am-sgmm2.cc:965