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 "Perform basis fMLLR adaptation in testing stage, either per utterance or\n" 59 "for the supplied set of speakers (spk2utt option). Reads Gaussian-level\n" 60 "posterior to accumulate fMLLR stats for each speaker/utterance. Writes\n" 61 "to a table of matrices.\n" 62 "Usage: gmm-est-basis-fmllr-gpost [options] <model-in> <basis-rspecifier> " 63 "<feature-rspecifier> <post-rspecifier> <transform-wspecifier>\n";
67 string spk2utt_rspecifier;
68 string weights_out_filename;
70 po.
Register(
"spk2utt", &spk2utt_rspecifier,
"Rspecifier for speaker to " 71 "utterance-list map");
72 po.
Register(
"write-weights", &weights_out_filename,
"File to write base " 84 model_rxfilename = po.
GetArg(1),
85 basis_rspecifier = po.
GetArg(2),
86 feature_rspecifier = po.
GetArg(3),
87 gpost_rspecifier = po.
GetArg(4),
88 trans_wspecifier = po.
GetArg(5);
90 TransitionModel trans_model;
94 Input ki(model_rxfilename, &binary);
95 trans_model.Read(ki.
Stream(), binary);
96 am_gmm.Read(ki.
Stream(), binary);
104 double tot_impr = 0.0, tot_t = 0.0;
108 if (!weights_out_filename.empty()) {
109 weights_writer.
Open(weights_out_filename);
112 int32 num_done = 0, num_no_post = 0, num_other_error = 0;
113 if (spk2utt_rspecifier !=
"") {
117 for (; !spk2utt_reader.
Done(); spk2utt_reader.
Next()) {
118 FmllrDiagGmmAccs spk_stats(am_gmm.Dim());
119 string spk = spk2utt_reader.
Key();
120 const vector<string> &uttlist = spk2utt_reader.
Value();
121 for (
size_t i = 0;
i < uttlist.size();
i++) {
122 std::string utt = uttlist[
i];
123 if (!feature_reader.
HasKey(utt)) {
124 KALDI_WARN <<
"Did not find features for utterance " << utt;
128 if (!gpost_reader.
HasKey(utt)) {
129 KALDI_WARN <<
"Did not find posteriors for utterance " << utt;
133 const Matrix<BaseFloat> &feats = feature_reader.
Value(utt);
135 if (static_cast<int32>(gpost.size()) != feats.NumRows()) {
136 KALDI_WARN <<
"GaussPost has wrong size " << (gpost.size())
137 <<
" vs. " << (feats.NumRows());
146 double impr, spk_tot_t; int32 wgt_size;
149 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim() + 1);
151 Vector<BaseFloat> weights;
153 &weights, basis_fmllr_opts);
154 spk_tot_t = spk_stats.beta_;
155 wgt_size = weights.Dim();
156 transform_writer.
Write(spk, transform);
158 if (!weights_out_filename.empty() && weights.Dim() > 0)
159 weights_writer.
Write(spk, weights);
162 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from Basis fMLLR is " 163 << (impr / spk_tot_t) <<
", over " << spk_tot_t <<
" frames, " 164 <<
"the top " << wgt_size <<
" basis elements have been used";
170 for (; !feature_reader.
Done(); feature_reader.
Next()) {
171 string utt = feature_reader.
Key();
172 if (!gpost_reader.
HasKey(utt)) {
173 KALDI_WARN <<
"Did not find posts for utterance " << utt;
177 const Matrix<BaseFloat> &feats = feature_reader.
Value();
180 if (static_cast<int32>(gpost.size()) != feats.NumRows()) {
181 KALDI_WARN <<
"GaussPost has wrong size " << (gpost.size())
182 <<
" vs. " << (feats.NumRows());
187 FmllrDiagGmmAccs spk_stats(am_gmm.Dim());
191 BaseFloat impr, utt_tot_t; int32 wgt_size;
193 Matrix<BaseFloat> transform(am_gmm.Dim(), am_gmm.Dim()+1);
195 Vector<BaseFloat> weights;
197 &weights, basis_fmllr_opts);
198 utt_tot_t = spk_stats.beta_;
199 wgt_size = weights.Dim();
200 transform_writer.
Write(utt, transform);
202 if (!weights_out_filename.empty() && weights.Dim() > 0)
203 weights_writer.
Write(utt, weights);
205 KALDI_LOG <<
"For utterance " << utt <<
", auxf-impr from Basis fMLLR is " 206 << (impr / utt_tot_t) <<
", over " << utt_tot_t <<
" frames, " 207 <<
"the top " << wgt_size <<
" basis elements have been used";
213 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_post
214 <<
" with no posts, " << num_other_error <<
" with other errors.";
215 KALDI_LOG <<
"Overall fMLLR auxf-impr per frame is " 216 << (tot_impr / tot_t) <<
" over " << tot_t <<
" frames.";
217 return (num_done != 0 ? 0 : 1);
218 }
catch(
const std::exception& e) {
219 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].
int main(int argc, char *argv[])
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...
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)
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)
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.
Estimation functions for basis fMLLR.