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 " 78 if (po.NumArgs() != 5) {
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);
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()) {
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;
134 const GaussPost &gpost = gpost_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;
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;
178 const GaussPost &gpost = gpost_reader.Value(utt);
180 if (static_cast<int32>(gpost.size()) != feats.
NumRows()) {
181 KALDI_WARN <<
"GaussPost has wrong size " << (gpost.size())
182 <<
" vs. " << (feats.
NumRows());
191 BaseFloat impr, utt_tot_t; int32 wgt_size;
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)
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...
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).
std::vector< std::vector< std::pair< int32, Vector< BaseFloat > > > > GaussPost
GaussPost is a typedef for storing Gaussian-level posteriors for an utterance.
void Read(std::istream &in_stream, bool binary)
Estimation functions for basis fMLLR.