55 using namespace kaldi;
59 "Initialize monophone GMM.\n" 60 "Usage: gmm-init-mono <topology-in> <dim> <model-out> <tree-out> \n" 62 " gmm-init-mono topo 39 mono.mdl mono.tree\n";
65 std::string train_feats;
66 std::string shared_phones_rxfilename;
69 po.Register(
"binary", &binary,
"Write output in binary mode");
70 po.Register(
"train-feats", &train_feats,
71 "rspecifier for training features [used to set mean and variance]");
72 po.Register(
"shared-phones", &shared_phones_rxfilename,
73 "rxfilename containing, on each line, a list of phones whose pdfs should be shared.");
74 po.Register(
"perturb-factor", &perturb_factor,
75 "Perturb the means using this fraction of standard deviation.");
78 if (po.NumArgs() != 4) {
84 std::string topo_filename = po.GetArg(1);
85 int dim = atoi(po.GetArg(2).c_str());
87 std::string model_filename = po.GetArg(3);
88 std::string tree_filename = po.GetArg(4);
91 glob_inv_var.Set(1.0);
95 if (train_feats !=
"") {
100 for (; !feat_reader.Done(); feat_reader.Next()) {
104 var_stats.AddVec2(1.0, mat.
Row(
i));
105 mean_stats.AddVec(1.0, mat.
Row(
i));
108 if (count == 0) {
KALDI_ERR <<
"no features were seen."; }
109 var_stats.Scale(1.0/count);
110 mean_stats.Scale(1.0/count);
111 var_stats.AddVec2(-1.0, mean_stats);
112 if (var_stats.Min() <= 0.0)
114 var_stats.InvertElements();
115 glob_inv_var.CopyFromVec(var_stats);
116 glob_mean.CopyFromVec(mean_stats);
121 Input ki(topo_filename, &binary_in);
122 topo.
Read(ki.Stream(), binary_in);
124 const std::vector<int32> &phones = topo.
GetPhones();
126 std::vector<int32> phone2num_pdf_classes (1+phones.back());
127 for (
size_t i = 0;
i < phones.size();
i++)
132 if (shared_phones_rxfilename ==
"") {
135 std::vector<std::vector<int32> > shared_phones;
148 inv_var.Row(0).CopyFromVec(glob_inv_var);
150 mu.Row(0).CopyFromVec(glob_mean);
158 for (
int i = 0; i < num_pdfs; i++)
161 if (perturb_factor != 0.0) {
162 for (
int i = 0; i < num_pdfs; i++)
170 Output ko(model_filename, binary);
171 trans_model.Write(ko.Stream(), binary);
172 am_gmm.
Write(ko.Stream(), binary);
176 ctx_dep->
Write(
Output(tree_filename, binary).Stream(),
181 }
catch(
const std::exception &e) {
182 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void AddPdf(const DiagGmm &gmm)
Adds a GMM to the model, and increments the total number of PDFs.
void Perturb(float perturb_factor)
Perturbs the component means with a random vector multiplied by the pertrub factor.
void SetInvVarsAndMeans(const MatrixBase< Real > &invvars, const MatrixBase< Real > &means)
Use SetInvVarsAndMeans if updating both means and (inverse) variances.
A class for storing topology information for phones.
ContextDependency * MonophoneContextDependency(const std::vector< int32 > &phones, const std::vector< int32 > &phone2num_pdf_classes)
void Resize(int32 nMix, int32 dim)
Resizes arrays to this dim. Does not initialize data.
ContextDependency * MonophoneContextDependencyShared(const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes)
int32 ComputeGconsts()
Sets the gconsts.
void Read(std::istream &is, bool binary)
int32 NumPdfClasses(int32 phone) const
Returns the number of pdf-classes for this phone; throws exception if phone not covered by this topol...
void ReadSharedPhonesList(std::string rxfilename, std::vector< std::vector< int32 > > *list_out)
virtual int32 NumPdfs() const
NumPdfs() returns the number of acoustic pdfs (they are numbered 0.. NumPdfs()-1).
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Write(std::ostream &os, bool binary) const
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
const std::vector< int32 > & GetPhones() const
Returns a reference to a sorted, unique list of phones covered by the topology (these phones will be ...
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Write(std::ostream &out_stream, bool binary) const
Definition for Gaussian Mixture Model with diagonal covariances.
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.