gmm-global-est.cc
Go to the documentation of this file.
1 // gmmbin/gmm-global-est.cc
2 
3 // Copyright 2009-2011 Saarland University; Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #include "base/kaldi-common.h"
21 #include "util/common-utils.h"
22 #include "gmm/diag-gmm.h"
23 #include "gmm/mle-diag-gmm.h"
24 
25 int main(int argc, char *argv[]) {
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 }
96 
97 
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...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
kaldi::int32 int32
int main(int argc, char *argv[])
void Register(const std::string &name, bool *ptr, const std::string &doc)
const size_t count
std::istream & Stream()
Definition: kaldi-io.cc:826
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
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
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
int NumArgs() const
Number of positional parameters (c.f. argc-1).
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