37 const TransitionModel &trans_model,
38 const AmDiagGmm &am_gmm,
39 FmllrDiagGmmAccs *spk_stats) {
42 for (
size_t i = 0;
i < post.size();
i++) {
43 for (
size_t j = 0;
j < pdf_post[
i].size();
j++) {
44 int32 pdf_id = pdf_post[
i][
j].first;
45 spk_stats->AccumulateForGmm(am_gmm.GetPdf(pdf_id),
47 pdf_post[
i][
j].second);
55 int main(
int argc,
char *argv[]) {
58 using namespace kaldi;
60 "Estimate global fMLLR transforms, either per utterance or for the supplied\n" 61 "set of speakers (spk2utt option). Reads posteriors (on transition-ids). Writes\n" 62 "to a table of matrices.\n" 63 "Usage: gmm-est-fmllr [options] <model-in> " 64 "<feature-rspecifier> <post-rspecifier> <transform-wspecifier>\n";
68 string spk2utt_rspecifier;
69 po.
Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to " 70 "utterance-list map");
81 model_rxfilename = po.
GetArg(1),
82 feature_rspecifier = po.
GetArg(2),
83 post_rspecifier = po.
GetArg(3),
84 trans_wspecifier = po.
GetArg(4);
86 TransitionModel trans_model;
90 Input ki(model_rxfilename, &binary);
91 trans_model.Read(ki.
Stream(), binary);
92 am_gmm.Read(ki.
Stream(), binary);
97 double tot_impr = 0.0, tot_t = 0.0;
101 int32 num_done = 0, num_no_post = 0, num_other_error = 0;
102 if (spk2utt_rspecifier !=
"") {
106 for (; !spk2utt_reader.
Done(); spk2utt_reader.
Next()) {
107 FmllrDiagGmmAccs spk_stats(am_gmm.Dim(), fmllr_opts);
108 string spk = spk2utt_reader.
Key();
109 const vector<string> &uttlist = spk2utt_reader.
Value();
110 for (
size_t i = 0;
i < uttlist.size();
i++) {
111 std::string utt = uttlist[
i];
112 if (!feature_reader.
HasKey(utt)) {
113 KALDI_WARN <<
"Did not find features for utterance " << utt;
117 if (!post_reader.
HasKey(utt)) {
118 KALDI_WARN <<
"Did not find posteriors for utterance " << utt;
122 const Matrix<BaseFloat> &feats = feature_reader.
Value(utt);
124 if (static_cast<int32>(post.size()) != feats.NumRows()) {
125 KALDI_WARN <<
"Posterior vector has wrong size " << (post.size())
126 <<
" vs. " << (feats.NumRows());
138 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim()+1);
140 spk_stats.Update(fmllr_opts, &transform, &impr, &spk_tot_t);
141 transform_writer.
Write(spk, transform);
143 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from fMLLR is " 144 << (impr/spk_tot_t) <<
", over " << spk_tot_t <<
" frames.";
150 for (; !feature_reader.
Done(); feature_reader.
Next()) {
151 string utt = feature_reader.
Key();
152 if (!post_reader.
HasKey(utt)) {
153 KALDI_WARN <<
"Did not find posts for utterance " 158 const Matrix<BaseFloat> &feats = feature_reader.
Value();
161 if (static_cast<int32>(post.size()) != feats.NumRows()) {
162 KALDI_WARN <<
"Posterior has wrong size " << (post.size())
163 <<
" vs. " << (feats.NumRows());
169 FmllrDiagGmmAccs spk_stats(am_gmm.Dim(), fmllr_opts);
176 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim()+1);
178 spk_stats.Update(fmllr_opts, &transform, &impr, &utt_tot_t);
179 transform_writer.
Write(utt, transform);
181 KALDI_LOG <<
"For utterance " << utt <<
", auxf-impr from fMLLR is " 182 << (impr/utt_tot_t) <<
", over " << utt_tot_t <<
" frames.";
188 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_post
189 <<
" with no posts, " << num_other_error <<
" with other errors.";
190 KALDI_LOG <<
"Overall fMLLR auxf impr per frame is " 191 << (tot_impr / tot_t) <<
" over " << tot_t <<
" frames.";
192 return (num_done != 0 ? 0 : 1);
193 }
catch(
const std::exception &e) {
194 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 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...
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...
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).
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.