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 "Perform basis fMLLR adaptation in testing stage, either per utterance or\n" 61 "for the supplied set of speakers (spk2utt option). Reads posterior to\n" 62 "accumulate fMLLR stats for each speaker/utterance. Writes to a table of\n" 64 "Usage: gmm-est-basis-fmllr [options] <model-in> <basis-rspecifier> <feature-rspecifier> " 65 "<post-rspecifier> <transform-wspecifier>\n";
69 string spk2utt_rspecifier;
70 string weights_out_filename;
72 po.
Register(
"spk2utt", &spk2utt_rspecifier,
"Rspecifier for speaker to " 73 "utterance-list map");
74 po.
Register(
"write-weights", &weights_out_filename,
"File to write base " 86 model_rxfilename = po.
GetArg(1),
87 basis_rspecifier = po.
GetArg(2),
88 feature_rspecifier = po.
GetArg(3),
89 post_rspecifier = po.
GetArg(4),
90 trans_wspecifier = po.
GetArg(5);
92 TransitionModel trans_model;
96 Input ki(model_rxfilename, &binary);
97 trans_model.Read(ki.
Stream(), binary);
98 am_gmm.Read(ki.
Stream(), binary);
106 double tot_impr = 0.0, tot_t = 0.0;
110 if (!weights_out_filename.empty()) {
111 weights_writer.
Open(weights_out_filename);
114 int32 num_done = 0, num_no_post = 0, num_other_error = 0;
115 if (spk2utt_rspecifier !=
"") {
119 for (; !spk2utt_reader.
Done(); spk2utt_reader.
Next()) {
120 FmllrDiagGmmAccs spk_stats(am_gmm.Dim());
121 string spk = spk2utt_reader.
Key();
122 const vector<string> &uttlist = spk2utt_reader.
Value();
123 for (
size_t i = 0;
i < uttlist.size();
i++) {
124 std::string utt = uttlist[
i];
125 if (!feature_reader.
HasKey(utt)) {
126 KALDI_WARN <<
"Did not find features for utterance " << utt;
130 if (!post_reader.
HasKey(utt)) {
131 KALDI_WARN <<
"Did not find posteriors for utterance " << utt;
135 const Matrix<BaseFloat> &feats = feature_reader.
Value(utt);
137 if (static_cast<int32>(post.size()) != feats.NumRows()) {
138 KALDI_WARN <<
"Posterior vector has wrong size " << (post.size())
139 <<
" vs. " << (feats.NumRows());
148 double impr, spk_tot_t; int32 wgt_size;
151 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim() + 1);
155 &weights, basis_fmllr_opts);
156 spk_tot_t = spk_stats.beta_;
157 wgt_size = weights.
Dim();
158 transform_writer.
Write(spk, transform);
160 if (!weights_out_filename.empty() && weights.
Dim() > 0)
161 weights_writer.
Write(spk, weights);
163 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from Basis fMLLR is " 164 << (impr / spk_tot_t) <<
", over " << spk_tot_t <<
" frames, " 165 <<
"the top " << wgt_size <<
" basis elements have been used";
171 for (; !feature_reader.
Done(); feature_reader.
Next()) {
172 string utt = feature_reader.
Key();
173 if (!post_reader.
HasKey(utt)) {
174 KALDI_WARN <<
"Did not find posts for utterance " << utt;
178 const Matrix<BaseFloat> &feats = feature_reader.
Value();
181 if (static_cast<int32>(post.size()) != feats.NumRows()) {
182 KALDI_WARN <<
"Posterior has wrong size " << (post.size())
183 <<
" vs. " << (feats.NumRows());
188 FmllrDiagGmmAccs spk_stats(am_gmm.Dim());
192 BaseFloat impr, utt_tot_t; int32 wgt_size;
194 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim()+1);
198 &weights, basis_fmllr_opts);
199 utt_tot_t = spk_stats.beta_;
200 wgt_size = weights.
Dim();
201 transform_writer.
Write(utt, transform);
203 if (!weights_out_filename.empty() && weights.
Dim() > 0)
204 weights_writer.
Write(utt, weights);
206 KALDI_LOG <<
"For utterance " << utt <<
", auxf-impr from Basis fMLLR is " 207 << (impr / utt_tot_t) <<
", over " << utt_tot_t <<
" frames, " 208 <<
"the top " << wgt_size <<
" basis elements have been used";
214 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_post
215 <<
" with no posts, " << num_other_error <<
" with other errors.";
216 KALDI_LOG <<
"Overall fMLLR auxf-impr per frame is " 217 << (tot_impr / tot_t) <<
" over " << tot_t <<
" frames.";
218 return (num_done != 0 ? 0 : 1);
219 }
catch(
const std::exception& e) {
220 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool Open(const std::string &wspecifier)
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...
double ComputeTransform(const AffineXformStats &spk_stats, Matrix< BaseFloat > *out_xform, Vector< BaseFloat > *coefficients, BasisFmllrOptions options) const
This function performs speaker adaptation, computing the fMLLR matrix based on speaker statistics...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
const T & Value(const std::string &key)
void Register(OptionsItf *opts)
int main(int argc, char *argv[])
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.
MatrixIndexT Dim() const
Returns the dimension of the vector.
bool HasKey(const std::string &key)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
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.
Estimation functions for basis fMLLR.