37 const std::vector<std::vector<int32> > &gselect,
48 for (
size_t t = 0; t < post.size(); t++) {
52 *spk_vars, &per_frame_vars);
55 for (
size_t j = 0;
j < pdf_post[t].size();
j++) {
56 int32 pdf_id = pdf_post[t][
j].first;
59 spk_vars, &posteriors);
60 posteriors.
Scale(pdf_post[t][
j].second);
62 gselect[t], posteriors, pdf_id);
69 int main(
int argc,
char *argv[]) {
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)");
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);
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)) {
164 logdet = fmllr_xform.
Range(0, dim, 0, dim).LogDet();
166 KALDI_WARN <<
"Cannot find FMLLR transform for " << spk;
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) ||
185 KALDI_WARN <<
"Did not find posteriors for utterance " << utt
186 <<
" (or wrong size).";
191 if (!gselect_reader.
HasKey(utt) ||
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) ||
228 KALDI_WARN <<
"Did not find posteriors for utterance " << utt
229 <<
" (or wrong size).";
234 if (!gselect_reader.
HasKey(utt) ||
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)) {
247 logdet = fmllr_xform.
Range(0, dim, 0, dim).LogDet();
249 KALDI_WARN <<
"Cannot find FMLLR transform for " << utt;
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...
BaseFloat ComponentPosteriors(const Sgmm2PerFrameDerivedVars &per_frame_vars, int32 j2, Sgmm2PerSpkDerivedVars *spk_vars, Matrix< BaseFloat > *post) const
Similar to LogLikelihood() function above, but also computes the posterior probabilities for the pre-...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
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)
void AccumulateFromPosteriors(const AmSgmm2 &sgmm, const Sgmm2PerSpkDerivedVars &spk, const VectorBase< BaseFloat > &data, const std::vector< int32 > &gauss_select, const Matrix< BaseFloat > &posteriors, int32 state_index)
A templated class for writing objects to an archive or script file; see The Table concept...
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void Register(OptionsItf *opts)
void ComputePerSpkDerivedVars(Sgmm2PerSpkDerivedVars *vars) const
Computes the per-speaker derived vars; assumes vars->v_s is already set up.
void SetUnit()
Sets to zero, except ones along diagonal [for non-square matrices too].
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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)
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
const T & Value(const std::string &key)
void Scale(Real alpha)
Multiply each element with a scalar value.
void Read(std::istream &is, bool binary)
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.
void ComputePerFrameVars(const VectorBase< BaseFloat > &data, const std::vector< int32 > &gselect, const Sgmm2PerSpkDerivedVars &spk_vars, Sgmm2PerFrameDerivedVars *per_frame_vars) const
This needs to be called with each new frame of data, prior to accumulation or likelihood evaluation: ...
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 main(int argc, char *argv[])
Configuration variables needed in the estimation of FMLLR for SGMMs.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of 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 ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
void Init(int32 dim, int32 num_gaussians)
Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf...
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...