30 int main(
int argc,
char *argv[]) {
31 using namespace kaldi;
35 "Accumulate stats for GMM training.\n" 36 "Usage: gmm-acc-stats-ali [options] <model-in> <feature-rspecifier> " 37 "<alignments-rspecifier> <stats-out>\n" 38 "e.g.:\n gmm-acc-stats-ali 1.mdl scp:train.scp ark:1.ali 1.acc\n";
42 po.
Register(
"binary", &binary,
"Write output in binary mode");
50 std::string model_filename = po.
GetArg(1),
51 feature_rspecifier = po.
GetArg(2),
52 alignments_rspecifier = po.
GetArg(3),
53 accs_wxfilename = po.
GetArg(4);
59 Input ki(model_filename, &binary);
69 double tot_like = 0.0;
70 kaldi::int64 tot_t = 0;
75 int32 num_done = 0, num_err = 0;
76 for (; !feature_reader.
Done(); feature_reader.
Next()) {
77 std::string key = feature_reader.
Key();
78 if (!alignments_reader.
HasKey(key)) {
79 KALDI_WARN <<
"No alignment for utterance " << key;
83 const std::vector<int32> &alignment = alignments_reader.
Value(key);
85 if (alignment.size() != mat.
NumRows()) {
86 KALDI_WARN <<
"Alignments has wrong size " << (alignment.size())
95 for (
size_t i = 0;
i < alignment.size();
i++) {
96 int32 tid = alignment[
i],
98 trans_model.
Accumulate(1.0, tid, &transition_accs);
102 tot_like += tot_like_this_file;
103 tot_t += alignment.size();
104 if (num_done % 50 == 0) {
105 KALDI_LOG <<
"Processed " << num_done <<
" utterances; for utterance " 106 << key <<
" avg. like is " 107 << (tot_like_this_file/alignment.size())
108 <<
" over " << alignment.size() <<
" frames.";
112 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_err
115 KALDI_LOG <<
"Overall avg like per frame (Gaussian only) = " 116 << (tot_like/tot_t) <<
" over " << tot_t <<
" frames.";
119 Output ko(accs_wxfilename, binary);
128 }
catch(
const std::exception &e) {
129 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int main(int argc, char *argv[])
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
BaseFloat AccumulateForGmm(const AmDiagGmm &model, const VectorBase< BaseFloat > &data, int32 gmm_index, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
int32 TransitionIdToPdf(int32 trans_id) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void InitStats(Vector< double > *stats) const
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
const T & Value(const std::string &key)
void Read(std::istream &is, bool binary)
void Accumulate(BaseFloat prob, int32 trans_id, Vector< double > *stats) 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.
bool HasKey(const std::string &key)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Write(std::ostream &out_stream, bool binary) const
void Read(std::istream &in_stream, bool binary)
void Init(const AmDiagGmm &model, GmmFlagsType flags)
Initializes accumulators for each GMM based on the number of components and dimension.