32 using namespace kaldi;
35 "Accumulate stats for GMM training, computing posteriors with one set of features\n" 36 "but accumulating statistics with another.\n" 37 "First features are used to get posteriors, second to accumulate stats\n" 38 "Usage: gmm-acc-stats-twofeats [options] <model-in> <feature1-rspecifier> <feature2-rspecifier> <posteriors-rspecifier> <stats-out>\n" 40 " gmm-acc-stats-twofeats 1.mdl 1.ali scp:train.scp scp:train_new.scp ark:1.ali 1.acc\n";
44 po.Register(
"binary", &binary,
"Write output in binary mode");
47 if (po.NumArgs() != 5) {
52 std::string model_filename = po.GetArg(1),
53 feature1_rspecifier = po.GetArg(2),
54 feature2_rspecifier = po.GetArg(3),
55 posteriors_rspecifier = po.GetArg(4),
56 accs_wxfilename = po.GetArg(5);
58 using namespace kaldi;
65 Input ki(model_filename, &binary);
66 trans_model.
Read(ki.Stream(), binary);
67 am_gmm.
Read(ki.Stream(), binary);
76 double tot_like = 0.0;
83 int32 num_done = 0, num_no2ndfeats = 0, num_no_posterior = 0, num_other_error = 0;
84 for (; !feature1_reader.Done(); feature1_reader.Next()) {
85 std::string key = feature1_reader.Key();
86 if (!feature2_reader.HasKey(key)) {
87 KALDI_WARN <<
"For utterance " << key <<
", second features not present.";
89 }
else if (!posteriors_reader.HasKey(key)) {
99 const Posterior &posterior = posteriors_reader.Value(key);
101 if (posterior.size() != mat1.
NumRows()) {
102 KALDI_WARN <<
"Posteriors has wrong size "<< (posterior.size()) <<
" vs. "<< (mat1.
NumRows());
107 KALDI_WARN <<
"Features have mismatched numbers of frames " 115 tot_weight_this_file = 0.0;
119 for (
size_t i = 0;
i < posterior.size();
i++) {
121 for (
size_t j = 0;
j <pdf_posterior[
i].size();
j++) {
122 int32 pdf_id = pdf_posterior[
i][
j].first;
124 tot_like_this_file += weight *
130 tot_weight_this_file += weight;
134 for (
size_t j = 0;
j < posterior[
i].size();
j++) {
135 int32 tid = posterior[
i][
j].first;
137 trans_model.
Accumulate(weight, tid, &transition_accs);
140 KALDI_LOG <<
"Average like for this file is " 141 << (tot_like_this_file/tot_weight_this_file) <<
" over " 142 << tot_weight_this_file <<
" frames.";
143 tot_like += tot_like_this_file;
144 tot_t += tot_weight_this_file;
145 if (num_done % 10 == 0)
146 KALDI_LOG <<
"Avg like per frame so far is " << (tot_like/tot_t);
150 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_posterior
151 <<
" with no posteriors, " << num_no2ndfeats
152 <<
" with no second features, " << num_other_error
153 <<
" with other errors.";
155 KALDI_LOG <<
"Overall avg like per frame (Gaussian only) = " 156 << (tot_like/tot_t) <<
" over " << tot_t <<
" frames.";
159 Output ko(accs_wxfilename, binary);
160 transition_accs.
Write(ko.Stream(), binary);
161 gmm_accs.
Write(ko.Stream(), binary);
164 if (num_done != 0)
return 0;
166 }
catch(
const std::exception &e) {
167 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
BaseFloat AccumulateForGmmTwofeats(const AmDiagGmm &model, const VectorBase< BaseFloat > &data1, const VectorBase< BaseFloat > &data2, int32 gmm_index, BaseFloat weight)
Accumulate stats for a single GMM in the model; uses data1 for getting posteriors and data2 for stats...
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
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...
#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
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
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.