30 using namespace kaldi;
32 typedef kaldi::int64 int64;
35 "Accumulate stats for GMM training (from posteriors)\n" 36 "This version writes two accumulators (e.g. num and den),\n" 37 "and puts the positive accumulators in num, negative in den\n" 38 "Usage: gmm-acc-stats2 [options] <model> <feature-rspecifier>" 39 "<posteriors-rspecifier> <num-stats-out> <den-stats-out>\n" 41 "gmm-acc-stats 1.mdl \"$feats\" ark:1.post 1.num_acc 1.den_acc\n";
45 std::string update_flags_str =
"mvwt";
47 po.Register(
"binary", &binary,
"Write stats in binary mode");
48 po.Register(
"update-flags", &update_flags_str,
"Which GMM parameters to " 49 "update: subset of mvwt.");
52 if (po.NumArgs() != 5) {
57 std::string model_rxfilename = po.GetArg(1),
58 feature_rspecifier = po.GetArg(2),
59 posteriors_rspecifier = po.GetArg(3),
60 num_accs_wxfilename = po.GetArg(4),
61 den_accs_wxfilename = po.GetArg(5);
68 Input ki(model_rxfilename, &binary);
69 trans_model.
Read(ki.Stream(), binary);
70 am_gmm.
Read(ki.Stream(), binary);
84 BaseFloat tot_like = 0.0, tot_weight = 0.0;
88 int64 tot_frames = 0.0;
90 int32 num_done = 0, num_err = 0;
91 for (; !feature_reader.Done(); feature_reader.Next()) {
92 std::string key = feature_reader.Key();
93 if (!posteriors_reader.HasKey(key)) {
97 const Posterior &posterior = posteriors_reader.Value(key);
99 if (static_cast<int32>(posterior.size()) != mat.
NumRows()) {
100 KALDI_WARN <<
"Posterior vector has wrong size " 101 << (posterior.size()) <<
" vs. " 107 BaseFloat tot_like_this_file = 0.0, tot_weight_this_file = 0.0;
110 for (
size_t i = 0;
i < posterior.size();
i++) {
111 for (
size_t j = 0;
j < posterior[
i].size();
j++) {
112 int32 tid = posterior[
i][
j].first,
117 &num_trans_accs : &den_trans_accs));
118 tot_like_this_file +=
119 (weight > 0.0 ? &num_gmm_accs : &den_gmm_accs) ->
120 AccumulateForGmm(am_gmm, mat.
Row(
i), pdf_id, fabs(weight)) * weight;
121 tot_weight_this_file += weight;
124 tot_like += tot_like_this_file;
125 tot_weight += tot_weight_this_file;
126 tot_frames +=
static_cast<int32
>(posterior.size());
130 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_err
133 KALDI_LOG <<
"Overall weighted acoustic likelihood per frame was " 134 << (tot_like/tot_frames) <<
" over " << tot_frames <<
" frames;" 135 <<
" average weight per frame was " << (tot_weight / tot_frames);
138 Output ko(num_accs_wxfilename, binary);
139 num_trans_accs.
Write(ko.Stream(), binary);
140 num_gmm_accs.
Write(ko.Stream(), binary);
143 Output ko(den_accs_wxfilename, binary);
144 den_trans_accs.
Write(ko.Stream(), binary);
145 den_gmm_accs.
Write(ko.Stream(), binary);
148 return (num_done != 0 ? 0 : 1);
149 }
catch(
const std::exception &e) {
150 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
GmmFlagsType StringToGmmFlags(std::string str)
Convert string which is some subset of "mSwa" to flags.
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
int32 TransitionIdToPdf(int32 trans_id) const
Allows random access to a collection of objects in an archive or script file; see The Table concept...
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
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].
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...
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.