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

References ParseOptions::GetArg(), kaldi::GetStatsDerivative(), KALDI_LOG, MleDiagGmmOptions::min_gaussian_occupancy, MleDiagGmmOptions::min_variance, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), AccumAmDiagGmm::Read(), AmDiagGmm::Read(), ParseOptions::Read(), TransitionModel::Read(), Vector< Real >::Read(), ParseOptions::Register(), Input::Stream(), and kaldi::WriteKaldiObject().

27  {
28  try {
29  using namespace kaldi;
30  typedef kaldi::int32 int32;
31  MleDiagGmmOptions gmm_opts;
32 
33  const char *usage =
34  "Get statistics derivative for GMM models\n"
35  "(used in fMPE/fMMI feature-space discriminative training)\n"
36  "Usage: gmm-get-stats-deriv [options] <model-in> <num-stats-in>"
37  " <den-stats-in> <ml-stats-in> <deriv-out>\n"
38  "e.g. (for fMMI/fBMMI): gmm-get-stats-deriv 1.mdl 1.acc 2.mdl\n";
39 
40  bool binary_write = true;
41  MleDiagGmmOptions opts; // Not passed to command-line-- just a mechanism to
42  // ensure our options have the same default values as those ones.
43  BaseFloat min_variance = opts.min_variance;
44  BaseFloat min_gaussian_occupancy = opts.min_gaussian_occupancy;
45 
46  ParseOptions po(usage);
47  po.Register("binary", &binary_write, "Write output in binary mode");
48  po.Register("min-variance", &min_variance,
49  "Variance floor (absolute variance).");
50  po.Register("min-gaussian-occupancy", &min_gaussian_occupancy,
51  "Minimum occupancy to update a Gaussian.");
52 
53  po.Read(argc, argv);
54 
55  if (po.NumArgs() != 5) {
56  po.PrintUsage();
57  exit(1);
58  }
59 
60  std::string model_rxfilename = po.GetArg(1),
61  num_stats_rxfilename = po.GetArg(2),
62  den_stats_rxfilename = po.GetArg(3),
63  ml_stats_rxfilename = po.GetArg(4),
64  deriv_wxfilename = po.GetArg(5);
65 
66  AmDiagGmm am_gmm;
67  TransitionModel trans_model;
68  {
69  bool binary_read;
70  Input ki(model_rxfilename, &binary_read);
71  trans_model.Read(ki.Stream(), binary_read);
72  am_gmm.Read(ki.Stream(), binary_read);
73  }
74 
75  Vector<double> transition_accs; // Reuse this for all transition accs we
76  // read, as it's not needed.
77  AccumAmDiagGmm num_stats, den_stats, ml_stats;
78  {
79  bool binary_read;
80  Input ki(num_stats_rxfilename, &binary_read);
81  transition_accs.Read(ki.Stream(), binary_read);
82  num_stats.Read(ki.Stream(), binary_read, false);
83  }
84  {
85  bool binary_read;
86  Input ki(den_stats_rxfilename, &binary_read);
87  transition_accs.Read(ki.Stream(), binary_read);
88  den_stats.Read(ki.Stream(), binary_read, false);
89  }
90  {
91  bool binary_read;
92  Input ki(ml_stats_rxfilename, &binary_read);
93  transition_accs.Read(ki.Stream(), binary_read);
94  ml_stats.Read(ki.Stream(), binary_read, false);
95  }
96 
97  AccumAmDiagGmm model_deriv; // Use GMM accumulators to represent
98  // derivative of discriminative objective function w.r.t.
99  // accumulated stats.
100 
101  GetStatsDerivative(am_gmm, num_stats, den_stats, ml_stats,
102  min_variance, min_gaussian_occupancy,
103  &model_deriv);
104 
105  WriteKaldiObject(model_deriv, deriv_wxfilename, binary_write);
106 
107  KALDI_LOG << "Computed model derivative and wrote it to "
108  << deriv_wxfilename;
109 
110  return 0;
111  } catch(const std::exception &e) {
112  std::cerr << e.what() << '\n';
113  return -1;
114  }
115 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
BaseFloat min_gaussian_occupancy
Minimum count below which a Gaussian is not updated (and is removed, if remove_low_count_gaussians ==...
Definition: mle-diag-gmm.h:47
double min_variance
Minimum allowed variance in any dimension (if no variance floor) It is in double since the variance i...
Definition: mle-diag-gmm.h:50
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void GetStatsDerivative(const DiagGmm &gmm, const AccumDiagGmm &num_acc, const AccumDiagGmm &den_acc, const AccumDiagGmm &ml_acc, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, AccumDiagGmm *out_accs)
void Read(std::istream &is, bool binary)
Configuration variables like variance floor, minimum occupancy, etc.
Definition: mle-diag-gmm.h:38
void Read(std::istream &in_stream, bool binary, bool add=false)
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:133
void Read(std::istream &in_stream, bool binary)
Definition: am-diag-gmm.cc:147
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.