29 using namespace kaldi;
33 "Accumulate stats for fMPE training, using GMM model. Note: this could\n" 34 "be done using gmm-get-feat-deriv and fmpe-acc-stats (but you'd be computing\n" 35 "the features twice). Features input should be pre-fMPE features.\n" 37 "Usage: gmm-fmpe-acc-stats [options] <model-in> <fmpe-in> <feature-rspecifier> " 38 "<gselect-rspecifier> <posteriors-rspecifier> <fmpe-stats-out>\n" 40 " gmm-fmpe-acc-stats --model-derivative 1.accs 1.mdl 1.fmpe \"$feats\" ark:1.gselect ark:1.post 1.fmpe_stats\n";
44 std::string model_derivative_rxfilename;
45 po.Register(
"binary", &binary,
"If true, write stats in binary mode.");
46 po.Register(
"model-derivative", &model_derivative_rxfilename,
47 "GMM-accs file containing model derivative [note: contains no transition stats]. Used for indirect differential. Warning: this will only work correctly in the case of MMI/BMMI objective function, with non-canceled stats.");
50 if (po.NumArgs() != 6) {
55 std::string model_rxfilename = po.GetArg(1),
56 fmpe_rxfilename = po.GetArg(2),
57 feature_rspecifier = po.GetArg(3),
58 gselect_rspecifier = po.GetArg(4),
59 posteriors_rspecifier = po.GetArg(5),
60 stats_wxfilename = po.GetArg(6);
66 Input ki(model_rxfilename, &binary);
67 trans_model.
Read(ki.Stream(), binary);
68 am_gmm.
Read(ki.Stream(), binary);
75 bool have_indirect = (model_derivative_rxfilename !=
"");
88 int32 num_done = 0, num_err = 0;
90 for (; !feature_reader.Done(); feature_reader.Next()) {
91 std::string key = feature_reader.Key();
92 if (!posteriors_reader.HasKey(key)) {
94 KALDI_WARN <<
"No posteriors for utterance " << key;
98 const Posterior &posterior = posteriors_reader.Value(key);
100 if (static_cast<int32>(posterior.size()) != feat_in.
NumRows()) {
101 KALDI_WARN <<
"Posterior vector has wrong size " <<
102 (posterior.size()) <<
" vs. "<< (feat_in.
NumRows());
107 if (!gselect_reader.HasKey(key)) {
108 KALDI_WARN <<
"No gselect information for key " << key;
112 const std::vector<std::vector<int32> > &gselect =
113 gselect_reader.Value(key);
114 if (static_cast<int32>(gselect.size()) != feat_in.
NumRows()) {
115 KALDI_WARN <<
"gselect information has wrong size";
123 fmpe_feat.AddMat(1.0, feat_in);
128 fmpe_feat, &direct_deriv,
129 (have_indirect ? &model_derivative : NULL),
130 (have_indirect ? &indirect_deriv : NULL));
131 num_frames += feat_in.
NumRows();
133 fmpe.
AccStats(feat_in, gselect, direct_deriv,
134 (have_indirect ? &indirect_deriv : NULL), &fmpe_stats);
136 if (num_done % 100 == 0)
137 KALDI_LOG <<
"Processed " << num_done <<
" utterances.";
140 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_err
142 KALDI_LOG <<
"Overall weighted acoustic likelihood per frame is " 143 << (tot_like/num_frames) <<
" over " << num_frames <<
" frames.";
145 Output ko(stats_wxfilename, binary);
146 fmpe_stats.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...
void ComputeFeatures(const MatrixBase< BaseFloat > &feat_in, const std::vector< std::vector< int32 > > &gselect, Matrix< BaseFloat > *feat_out) const
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
BaseFloat ComputeAmGmmFeatureDeriv(const AmDiagGmm &am_gmm, const TransitionModel &trans_model, const Posterior &posterior, const MatrixBase< BaseFloat > &features, Matrix< BaseFloat > *direct_deriv, const AccumAmDiagGmm *model_diff, Matrix< BaseFloat > *indirect_deriv)
Computes derivatives of the likelihood of these states (weighted), w.r.t.
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
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...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
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 Read(std::istream &in_stream, bool binary)
void AccStats(const MatrixBase< BaseFloat > &feat_in, const std::vector< std::vector< int32 > > &gselect, const MatrixBase< BaseFloat > &direct_feat_deriv, const MatrixBase< BaseFloat > *indirect_feat_deriv, FmpeStats *stats) const