gmm-est-rescale.cc File Reference
Include dependency graph for gmm-est-rescale.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 gmm-est-rescale.cc.

References kaldi::DoRescalingUpdate(), ParseOptions::GetArg(), 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(), Output::Stream(), Input::Stream(), AmDiagGmm::Write(), and TransitionModel::Write().

26  {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29  try {
30  const char *usage =
31  "Do \"re-scaling\" re-estimation of GMM-based model\n"
32  " (this update changes the model as features change, but preserves\n"
33  " the difference between the model and the features, to keep\n"
34  " the effect of any prior discriminative training). Used in fMPE.\n"
35  " Does not update the transitions or weights.\n"
36  "Usage: gmm-est-rescale [options] <model-in> <old-stats-in> <new-stats-in> <model-out>\n"
37  "e.g.: gmm-est-rescale 1.mdl old.acc new.acc 2.mdl\n";
38 
39  bool binary_write = true;
40  MleDiagGmmOptions opts; // Not passed to command-line-- just a mechanism to
41  // ensure our options have the same default values as those ones.
42  BaseFloat min_variance = opts.min_variance;
43  BaseFloat min_gaussian_occupancy = opts.min_gaussian_occupancy;
44 
45  ParseOptions po(usage);
46  po.Register("binary", &binary_write, "Write output in binary mode");
47  po.Register("min-variance", &min_variance,
48  "Variance floor (absolute variance).");
49  po.Register("min-gaussian-occupancy", &min_gaussian_occupancy,
50  "Minimum occupancy to update a Gaussian.");
51 
52  po.Read(argc, argv);
53 
54  if (po.NumArgs() != 4) {
55  po.PrintUsage();
56  exit(1);
57  }
58 
59  std::string model_rxfilename = po.GetArg(1),
60  old_stats_rxfilename = po.GetArg(2),
61  new_stats_rxfilename = po.GetArg(3),
62  model_wxfilename = po.GetArg(4);
63 
64  AmDiagGmm am_gmm;
65  TransitionModel trans_model;
66  {
67  bool binary_read;
68  Input ki(model_rxfilename, &binary_read);
69  trans_model.Read(ki.Stream(), binary_read);
70  am_gmm.Read(ki.Stream(), binary_read);
71  }
72 
73  AccumAmDiagGmm old_gmm_accs, new_gmm_accs;
74  {
75  Vector<double> transition_accs;
76  bool binary;
77  Input ki(old_stats_rxfilename, &binary);
78  transition_accs.Read(ki.Stream(), binary);
79  old_gmm_accs.Read(ki.Stream(), binary, true);
80  }
81  {
82  Vector<double> transition_accs;
83  bool binary;
84  Input ki(new_stats_rxfilename, &binary);
85  transition_accs.Read(ki.Stream(), binary);
86  new_gmm_accs.Read(ki.Stream(), binary, true);
87  }
88 
89  DoRescalingUpdate(old_gmm_accs, new_gmm_accs,
90  min_variance, min_gaussian_occupancy,
91  &am_gmm);
92 
93  {
94  Output ko(model_wxfilename, binary_write);
95  trans_model.Write(ko.Stream(), binary_write);
96  am_gmm.Write(ko.Stream(), binary_write);
97  }
98 
99  KALDI_LOG << "Rescaled model and wrote to " << model_wxfilename;
100  return 0;
101  } catch(const std::exception &e) {
102  std::cerr << e.what() << '\n';
103  return -1;
104  }
105 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
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
kaldi::int32 int32
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 DoRescalingUpdate(const AccumDiagGmm &old_ml_acc, const AccumDiagGmm &new_ml_acc, BaseFloat min_variance, BaseFloat min_gaussian_occupancy, DiagGmm *gmm, double *tot_count, double *tot_divergence)
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 Write(std::ostream &os, bool binary) const
void Write(std::ostream &out_stream, bool binary) const
Definition: am-diag-gmm.cc:163
#define KALDI_LOG
Definition: kaldi-error.h:153
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.