72 using namespace kaldi;
74 "Estimate FMLLR transform for SGMMs, either per utterance or for the " 75 "supplied set of speakers (with spk2utt option).\n" 76 "Reads state-level posteriors. Writes to a table of matrices.\n" 77 "--gselect option is mandatory.\n" 78 "Usage: sgmm2-est-fmllr [options] <model-in> <feature-rspecifier> " 79 "<post-rspecifier> <mats-wspecifier>\n";
82 string spk2utt_rspecifier, spkvecs_rspecifier, fmllr_rspecifier,
87 po.
Register(
"spk2utt", &spk2utt_rspecifier,
88 "File to read speaker to utterance-list map from.");
89 po.Register(
"spkvec-min-count", &min_count,
90 "Minimum count needed to estimate speaker vectors");
91 po.Register(
"spk-vecs", &spkvecs_rspecifier,
92 "Speaker vectors to use during aligment (rspecifier)");
93 po.Register(
"input-fmllr", &fmllr_rspecifier,
94 "Initial FMLLR transform per speaker (rspecifier)");
95 po.Register(
"gselect", &gselect_rspecifier,
96 "Precomputed Gaussian indices (rspecifier)");
101 if (po.NumArgs() != 4) {
106 string model_rxfilename = po.GetArg(1),
107 feature_rspecifier = po.GetArg(2),
108 post_rspecifier = po.GetArg(3),
109 fmllr_wspecifier = po.GetArg(4);
116 Input ki(model_rxfilename, &binary);
117 trans_model.
Read(ki.Stream(), binary);
118 am_sgmm.
Read(ki.Stream(), binary);
119 fmllr_globals.
Read(ki.Stream(), binary);
121 if (gselect_rspecifier ==
"")
122 KALDI_ERR <<
"--gselect option is required.";
136 double tot_impr = 0.0, tot_t = 0.0;
137 int32 num_done = 0, num_err = 0;
138 std::vector<std::vector<int32> > empty_gselect;
140 if (!spk2utt_rspecifier.empty()) {
144 for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
146 string spk = spk2utt_reader.Key();
147 const vector<string> &uttlist = spk2utt_reader.Value();
150 if (spkvecs_reader.IsOpen()) {
151 if (spkvecs_reader.HasKey(spk)) {
155 KALDI_WARN <<
"Cannot find speaker vector for " << spk;
161 if (fmllr_reader.IsOpen()) {
162 if (fmllr_reader.HasKey(spk)) {
163 fmllr_xform.CopyFromMat(fmllr_reader.Value(spk));
164 logdet = fmllr_xform.Range(0, dim, 0, dim).LogDet();
166 KALDI_WARN <<
"Cannot find FMLLR transform for " << spk;
167 fmllr_xform.SetUnit();
171 fmllr_xform.SetUnit();
175 for (
size_t i = 0;
i < uttlist.size();
i++) {
176 std::string utt = uttlist[
i];
177 if (!feature_reader.HasKey(utt)) {
178 KALDI_WARN <<
"Did not find features for utterance " << utt;
183 if (!post_reader.HasKey(utt) ||
184 post_reader.Value(utt).size() != feats.
NumRows()) {
185 KALDI_WARN <<
"Did not find posteriors for utterance " << utt
186 <<
" (or wrong size).";
190 const Posterior &post = post_reader.Value(utt);
191 if (!gselect_reader.HasKey(utt) ||
192 gselect_reader.Value(utt).size() != feats.
NumRows()) {
193 KALDI_WARN <<
"Did not find gselect info for utterance " << utt
194 <<
" (or wrong size).";
198 const std::vector<std::vector<int32> > &gselect =
199 gselect_reader.Value(utt);
202 for (int32 r = 0; r < transformed_feats.NumRows(); r++) {
207 post, trans_model, am_sgmm,
208 logdet, &spk_vars, &spk_stats);
214 spk_stats.
Update(am_sgmm, fmllr_globals, fmllr_opts, &fmllr_xform,
215 &spk_frame_count, &impr);
216 fmllr_writer.Write(spk, fmllr_xform);
218 tot_t += spk_frame_count;
222 for (; !feature_reader.Done(); feature_reader.Next()) {
223 string utt = feature_reader.Key();
226 if (!post_reader.HasKey(utt) ||
227 post_reader.Value(utt).size() != feats.
NumRows()) {
228 KALDI_WARN <<
"Did not find posteriors for utterance " << utt
229 <<
" (or wrong size).";
233 const Posterior &post = post_reader.Value(utt);
234 if (!gselect_reader.HasKey(utt) ||
235 gselect_reader.Value(utt).size() != feats.
NumRows()) {
236 KALDI_WARN <<
"Did not find gselect info for utterance " << utt
237 <<
" (or wrong size).";
241 const std::vector<std::vector<int32> > &gselect =
242 gselect_reader.Value(utt);
244 if (fmllr_reader.IsOpen()) {
245 if (fmllr_reader.HasKey(utt)) {
246 fmllr_xform.CopyFromMat(fmllr_reader.Value(utt));
247 logdet = fmllr_xform.Range(0, dim, 0, dim).LogDet();
249 KALDI_WARN <<
"Cannot find FMLLR transform for " << utt;
250 fmllr_xform.SetUnit();
254 fmllr_xform.SetUnit();
259 for (int32 r = 0; r < transformed_feats.NumRows(); r++) {
265 if (spkvecs_reader.IsOpen()) {
266 if (spkvecs_reader.HasKey(utt)) {
270 KALDI_WARN <<
"Cannot find speaker vector for " << utt;
279 post, trans_model, am_sgmm,
280 logdet, &spk_vars, &spk_stats);
285 spk_stats.
Update(am_sgmm, fmllr_globals, fmllr_opts, &fmllr_xform,
286 &spk_frame_count, &impr);
287 fmllr_writer.Write(utt, fmllr_xform);
289 tot_t += spk_frame_count;
293 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_err <<
" with errors.";
294 KALDI_LOG <<
"Overall auxf impr per frame is " << (tot_impr / tot_t)
295 <<
" per frame, over " << tot_t <<
" frames.";
296 return (num_done != 0 ? 0 : 1);
297 }
catch(
const std::exception &e) {
298 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Class for definition of the subspace Gmm acoustic model.
Class for computing the accumulators needed for the maximum-likelihood estimate of FMLLR transforms f...
void Read(std::istream &is, bool binary)
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 Register(OptionsItf *opts)
void ComputePerSpkDerivedVars(Sgmm2PerSpkDerivedVars *vars) const
Computes the per-speaker derived vars; assumes vars->v_s is already set up.
Allows random access to a collection of objects in an archive or script file; see The Table concept...
bool Update(const AmSgmm2 &model, const Sgmm2FmllrGlobalParams &fmllr_globals, const Sgmm2FmllrConfig &opts, Matrix< BaseFloat > *out_xform, BaseFloat *frame_count, BaseFloat *auxf_improv) const
Computes the FMLLR transform from the accumulated stats, using the pre-transforms in fmllr_globals...
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 &in_stream, bool binary)
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Configuration variables needed in the estimation of FMLLR for SGMMs.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void SetSpeakerVector(const Vector< BaseFloat > &v_s_in)
Global adaptation parameters.
void ApplyAffineTransform(const MatrixBase< BaseFloat > &xform, VectorBase< BaseFloat > *vec)
Applies the affine transform 'xform' to the vector 'vec' and overwrites the contents of 'vec'...
void Init(int32 dim, int32 num_gaussians)
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...