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

References count, ParseOptions::GetArg(), KALDI_LOG, kaldi::MleFullGmmUpdate(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), AccumFullGmm::Read(), ParseOptions::Read(), FullGmm::Read(), MleFullGmmOptions::Register(), ParseOptions::Register(), FullGmm::Split(), Input::Stream(), kaldi::StringToGmmFlags(), and kaldi::WriteKaldiObject().

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