36 Input input(rxfilename);
37 std::istream &is = input.Stream();
39 while (std::getline(is, line)) {
40 list_out->push_back(std::vector<int32>());
42 KALDI_ERR <<
"Bad line in shared phones list: " << line <<
" (reading " 44 std::sort(list_out->rbegin()->begin(), list_out->rbegin()->end());
46 KALDI_ERR <<
"Bad line in shared phones list (repeated phone): " << line
53 int main(
int argc,
char *argv[]) {
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.");
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()) {
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)
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);
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.
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int main(int argc, char *argv[])
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)
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
void Register(const std::string &name, bool *ptr, const std::string &doc)
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)
void AddVec2(const Real alpha, const VectorBase< Real > &v)
Add vector : *this = *this + alpha * rv^2 [element-wise squaring].
virtual int32 NumPdfs() const
NumPdfs() returns the number of acoustic pdfs (they are numbered 0.. NumPdfs()-1).
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
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...
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.
void Scale(Real alpha)
Multiplies all elements by this constant.
const std::vector< int32 > & GetPhones() const
Returns a reference to a sorted, unique list of phones covered by the topology (these phones will be ...
int NumArgs() const
Number of positional parameters (c.f. argc-1).
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
void Write(std::ostream &os, bool binary) const
A class representing a vector.
void InvertElements()
Invert all elements.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Set(Real f)
Set all members of a vector to a specified value.
void Write(std::ostream &out_stream, bool binary) const
Definition for Gaussian Mixture Model with diagonal covariances.
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
void SetWeights(const VectorBase< Real > &w)
Mutators for both float or double.
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once.
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...