37 const TransitionModel &trans_model,
38 const AmDiagGmm &am_gmm,
39 FmllrDiagGmmAccs *spk_stats) {
40 for (
size_t i = 0;
i < gpost.size();
i++) {
41 for (
size_t j = 0;
j < gpost[
i].size();
j++) {
42 int32 pdf_id = gpost[
i][
j].first;
43 const Vector<BaseFloat> & posterior(gpost[
i][
j].second);
44 spk_stats->AccumulateFromPosteriors(am_gmm.GetPdf(pdf_id),
45 feats.Row(
i), posterior);
53 int main(
int argc,
char *argv[]) {
56 using namespace kaldi;
58 "Estimate global fMLLR transforms, either per utterance or for the supplied\n" 59 "set of speakers (spk2utt option). Reads Gaussian-level posteriors. Writes\n" 60 "to a table of matrices.\n" 61 "Usage: gmm-est-fmllr-gpost [options] <model-in> " 62 "<feature-rspecifier> <gpost-rspecifier> <transform-wspecifier>\n";
66 string spk2utt_rspecifier;
67 po.
Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to " 68 "utterance-list map");
79 model_rxfilename = po.
GetArg(1),
80 feature_rspecifier = po.
GetArg(2),
81 gpost_rspecifier = po.
GetArg(3),
82 trans_wspecifier = po.
GetArg(4);
84 TransitionModel trans_model;
88 Input ki(model_rxfilename, &binary);
89 trans_model.Read(ki.
Stream(), binary);
90 am_gmm.Read(ki.
Stream(), binary);
95 double tot_impr = 0.0, tot_t = 0.0;
99 int32 num_done = 0, num_no_gpost = 0, num_other_error = 0;
100 if (spk2utt_rspecifier !=
"") {
104 for (; !spk2utt_reader.
Done(); spk2utt_reader.
Next()) {
105 FmllrDiagGmmAccs spk_stats(am_gmm.Dim());
106 string spk = spk2utt_reader.
Key();
107 const vector<string> &uttlist = spk2utt_reader.
Value();
108 for (
size_t i = 0;
i < uttlist.size();
i++) {
109 std::string utt = uttlist[
i];
110 if (!feature_reader.
HasKey(utt)) {
111 KALDI_WARN <<
"Did not find features for utterance " << utt;
115 if (!gpost_reader.
HasKey(utt)) {
116 KALDI_WARN <<
"Did not find posteriors for utterance " << utt;
120 const Matrix<BaseFloat> &feats = feature_reader.
Value(utt);
122 if (static_cast<int32>(gpost.size()) != feats.NumRows()) {
123 KALDI_WARN <<
"GaussPost vector has wrong size " << (gpost.size())
124 <<
" vs. " << (feats.NumRows());
136 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim()+1);
138 spk_stats.Update(fmllr_opts, &transform, &impr, &spk_tot_t);
139 transform_writer.
Write(spk, transform);
141 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from fMLLR is " 142 << (impr/spk_tot_t) <<
", over " << spk_tot_t <<
" frames.\n";
148 for (; !feature_reader.
Done(); feature_reader.
Next()) {
149 string utt = feature_reader.
Key();
150 if (!gpost_reader.
HasKey(utt)) {
151 KALDI_WARN <<
"Did not find gposts for utterance " 156 const Matrix<BaseFloat> &feats = feature_reader.
Value();
159 if (static_cast<int32>(gpost.size()) != feats.NumRows()) {
160 KALDI_WARN <<
"GaussPost has wrong size " << (gpost.size())
161 <<
" vs. " << (feats.NumRows());
167 FmllrDiagGmmAccs spk_stats(am_gmm.Dim());
174 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim()+1);
176 spk_stats.Update(fmllr_opts, &transform, &impr, &utt_tot_t);
177 transform_writer.
Write(utt, transform);
179 KALDI_LOG <<
"For utterancer " << utt <<
", auxf-impr from fMLLR is " 180 << (impr/utt_tot_t) <<
", over " << utt_tot_t <<
" frames.";
186 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_gpost
187 <<
" with no gposts, " << num_other_error <<
" with other errors.";
188 KALDI_LOG <<
"Overall fMLLR auxf impr per frame is " 189 << (tot_impr / tot_t) <<
" over " << tot_t <<
" frames.";
190 return (num_done != 0 ? 0 : 1);
191 }
catch(
const std::exception &e) {
192 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void AccumulateForUtterance(const Matrix< BaseFloat > &feats, const GaussPost &gpost, const TransitionModel &trans_model, const AmDiagGmm &am_gmm, FmllrDiagGmmAccs *spk_stats)
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) 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...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
int main(int argc, char *argv[])
const T & Value(const std::string &key)
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)
void Register(OptionsItf *opts)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
std::vector< std::vector< std::pair< int32, Vector< BaseFloat > > > > GaussPost
GaussPost is a typedef for storing Gaussian-level posteriors for an utterance.