29 using namespace kaldi;
34 "Initialize a full-covariance GMM from the accumulated stats.\n" 35 "This binary is similar to fgmm-global-est, but does not use " 36 "a preexisting model. See also fgmm-global-est.\n" 37 "Usage: fgmm-global-init-from-accs [options] <stats-in> " 38 "<number-of-components> <model-out>\n";
40 bool binary_write =
true;
42 po.Register(
"binary", &binary_write,
"Write output in binary mode");
47 if (po.NumArgs() != 3) {
52 std::string stats_filename = po.GetArg(1),
53 model_out_filename = po.GetArg(3);
54 int32 num_components = atoi(po.GetArg(2).c_str());
59 Input ki(stats_filename, &binary);
60 gmm_accs.Read(ki.Stream(), binary,
true );
63 int32 num_gauss = gmm_accs.NumGauss(), dim = gmm_accs.Dim(),
64 tot_floored = 0, gauss_floored = 0, tot_low_occ = 0;
66 FullGmm fgmm(num_components, dim);
70 std::vector<SpMatrix<BaseFloat> > invcovars;
72 for (int32
i = 0;
i < num_components;
i++) {
84 covar.AddDiagVec(1.0,
diag);
88 mean.CopyRowFromMat(gmm_accs.mean_accumulator(),
i);
89 mean.Scale(1.0 / occ);
90 covar.CopyFromSp(gmm_accs.covariance_accumulator()[
i]);
91 covar.Scale(1.0 / occ);
92 covar.AddVec2(-1.0, mean);
94 means.CopyRowFromVec(mean,
i);
99 static_cast<BaseFloat>(covar.MaxAbsEig() / gmm_opts.
max_condition));
100 int32 floored = covar.ApplyFloor(floor);
102 tot_floored += floored;
105 covar.InvertDouble();
106 invcovars.push_back(covar);
108 weights.Scale(1.0 / weights.Sum());
109 fgmm.SetWeights(weights);
110 fgmm.SetInvCovarsAndMeans(invcovars, means);
111 int32 num_bad = fgmm.ComputeGconsts();
112 KALDI_LOG <<
"FullGmm has " << num_bad <<
" bad GConsts";
114 if (tot_floored > 0) {
115 KALDI_WARN << tot_floored <<
" variances floored in " << gauss_floored
118 if (tot_low_occ > 0) {
119 KALDI_WARN << tot_low_occ <<
" out of " << num_gauss
120 <<
" Gaussians had very low occupancy.";
125 KALDI_LOG <<
"Written model to " << model_out_filename;
126 }
catch(
const std::exception &e) {
127 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Packed symetric matrix class.
Configuration variables like variance floor, minimum occupancy, etc.
Definition for Gaussian Mixture Model with full covariances.
BaseFloat variance_floor
Floor on eigenvalues of covariance matrices.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Register(OptionsItf *opts)
Class for computing the maximum-likelihood estimates of the parameters of a Gaussian mixture model...
A class representing a vector.
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
BaseFloat max_condition
Maximum condition number of covariance matrices (apply floor to eigenvalues if they pass this)...