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 " 80 if (po.NumArgs() != 5) {
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);
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()) {
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;
136 const Posterior &post = post_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;
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;
179 const Posterior &post = post_reader.Value(utt);
181 if (static_cast<int32>(post.size()) != feats.
NumRows()) {
182 KALDI_WARN <<
"Posterior has wrong size " << (post.size())
183 <<
" vs. " << (feats.
NumRows());
192 BaseFloat impr, utt_tot_t; int32 wgt_size;
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)
This does not work with multiple feature transforms.
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 SetUnit()
Sets to zero, except ones along diagonal [for non-square matrices too].
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 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)
void Register(OptionsItf *opts)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
MatrixIndexT Dim() const
Returns the dimension of the vector.
A class representing a vector.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Read(std::istream &in_stream, bool binary)
Estimation functions for basis fMLLR.