gmm-global-est.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "gmm/diag-gmm.h"
#include "gmm/mle-diag-gmm.h"
Include dependency graph for gmm-global-est.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 25 of file gmm-global-est.cc.

References count, ParseOptions::GetArg(), KALDI_LOG, kaldi::MleDiagGmmUpdate(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), AccumDiagGmm::Read(), DiagGmm::Read(), MleDiagGmmOptions::Register(), ParseOptions::Register(), DiagGmm::Split(), Input::Stream(), kaldi::StringToGmmFlags(), and kaldi::WriteKaldiObject().

25  {
26  try {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29 
30  MleDiagGmmOptions gmm_opts;
31 
32  const char *usage =
33  "Estimate a diagonal-covariance GMM from the accumulated stats.\n"
34  "Usage: gmm-global-est [options] <model-in> <stats-in> <model-out>\n";
35 
36  bool binary_write = true;
37  int32 mixup = 0;
38  BaseFloat perturb_factor = 0.01;
39  std::string update_flags_str = "mvw";
40  ParseOptions po(usage);
41  po.Register("binary", &binary_write, "Write output in binary mode");
42  po.Register("update-flags", &update_flags_str, "Which GMM parameters will be "
43  "updated: subset of mvw.");
44  po.Register("mix-up", &mixup, "Increase number of mixture components to "
45  "this overall target.");
46  po.Register("perturb-factor", &perturb_factor, "While mixing up, perturb "
47  "means by standard deviation times this factor.");
48  gmm_opts.Register(&po);
49 
50  po.Read(argc, argv);
51 
52  if (po.NumArgs() != 3) {
53  po.PrintUsage();
54  exit(1);
55  }
56 
57  std::string model_in_filename = po.GetArg(1),
58  stats_filename = po.GetArg(2),
59  model_out_filename = po.GetArg(3);
60 
61  DiagGmm gmm;
62  {
63  bool binary_read;
64  Input ki(model_in_filename, &binary_read);
65  gmm.Read(ki.Stream(), binary_read);
66  }
67 
68  AccumDiagGmm gmm_accs;
69  {
70  bool binary;
71  Input ki(stats_filename, &binary);
72  gmm_accs.Read(ki.Stream(), binary, true /* add accs, doesn't matter */);
73  }
74 
75  { // Update GMMs.
76  BaseFloat objf_impr, count;
77  MleDiagGmmUpdate(gmm_opts, gmm_accs,
78  StringToGmmFlags(update_flags_str),
79  &gmm, &objf_impr, &count);
80  KALDI_LOG << "Overall objective function improvement is "
81  << (objf_impr/count) << " per frame over "
82  << (count) << " frames.";
83  }
84 
85  if (mixup != 0)
86  gmm.Split(mixup, perturb_factor);
87 
88  WriteKaldiObject(gmm, model_out_filename, binary_write);
89 
90  KALDI_LOG << "Written model to " << model_out_filename;
91  } catch(const std::exception &e) {
92  std::cerr << e.what() << '\n';
93  return -1;
94  }
95 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Split(int32 target_components, float perturb_factor, std::vector< int32 > *history=NULL)
Split the components and remember the order in which the components were split.
Definition: diag-gmm.cc:154
GmmFlagsType StringToGmmFlags(std::string str)
Convert string which is some subset of "mSwa" to flags.
Definition: model-common.cc:26
void MleDiagGmmUpdate(const MleDiagGmmOptions &config, const AccumDiagGmm &diag_gmm_acc, GmmFlagsType flags, DiagGmm *gmm, BaseFloat *obj_change_out, BaseFloat *count_out, int32 *floored_elements_out, int32 *floored_gaussians_out, int32 *removed_gaussians_out)
for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
kaldi::int32 int32
const size_t count
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 Register(OptionsItf *opts)
Definition: mle-diag-gmm.h:59
Configuration variables like variance floor, minimum occupancy, etc.
Definition: mle-diag-gmm.h:38
void Read(std::istream &in_stream, bool binary, bool add)
Definition: mle-diag-gmm.cc:33
void Read(std::istream &in, bool binary)
Definition: diag-gmm.cc:728
Definition for Gaussian Mixture Model with diagonal covariances.
Definition: diag-gmm.h:42
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153