65     using namespace kaldi;
    67         "Estimate SGMM speaker vectors, either per utterance or for the "    68         "supplied set of speakers (with spk2utt option).\n"    69         "Reads Gaussian-level posteriors. Writes to a table of vectors.\n"    70         "Usage: sgmm2-est-spkvecs [options] <model-in> <feature-rspecifier> "    71         "<post-rspecifier> <vecs-wspecifier>\n"    72         "note: --gselect option is required.";
    75     string gselect_rspecifier, spk2utt_rspecifier, spkvecs_rspecifier;
    79     po.Register(
"gselect", &gselect_rspecifier,
    80                 "rspecifier for precomputed per-frame Gaussian indices from.");
    81     po.Register(
"spk2utt", &spk2utt_rspecifier,
    82         "File to read speaker to utterance-list map from.");
    83     po.Register(
"spkvec-min-count", &min_count,
    84         "Minimum count needed to estimate speaker vectors");
    85     po.Register(
"rand-prune", &rand_prune, 
"Pruning threshold for posteriors");
    86     po.Register(
"spk-vecs", &spkvecs_rspecifier, 
"Speaker vectors to use during aligment (rspecifier)");
    89     if (po.NumArgs() != 4) {
    93     if (gselect_rspecifier == 
"")
    94       KALDI_ERR << 
"--gselect option is mandatory.";
    96     string model_rxfilename = po.GetArg(1),
    97         feature_rspecifier = po.GetArg(2),
    98         post_rspecifier = po.GetArg(3),
    99         vecs_wspecifier = po.GetArg(4);
   105       Input ki(model_rxfilename, &binary);
   106       trans_model.
Read(ki.Stream(), binary);
   107       am_sgmm.
Read(ki.Stream(), binary);
   117     double tot_impr = 0.0, tot_t = 0.0;
   118     int32 num_done = 0, num_err = 0;
   119     std::vector<std::vector<int32> > empty_gselect;
   121     if (!spk2utt_rspecifier.empty()) {  
   125       for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
   127         string spk = spk2utt_reader.Key();
   128         const vector<string> &uttlist = spk2utt_reader.Value();
   131         if (spkvecs_reader.IsOpen()) {
   132           if (spkvecs_reader.HasKey(spk)) {
   136             KALDI_WARN << 
"Cannot find speaker vector for speaker " << spk
   137                        << 
", not processing this speaker.";
   144         for (
size_t i = 0; 
i < uttlist.size(); 
i++) {
   145           std::string utt = uttlist[
i];
   146           if (!feature_reader.HasKey(utt)) {
   147             KALDI_WARN << 
"Did not find features for utterance " << utt;
   150           if (!post_reader.HasKey(utt)) {
   151             KALDI_WARN << 
"Did not find posteriors for utterance " << utt;
   156           const Posterior &post = post_reader.Value(utt);
   157           if (static_cast<int32>(post.size()) != feats.
NumRows()) {
   158             KALDI_WARN << 
"Posterior vector has wrong size " << (post.size())
   159                        << 
" vs. " << (feats.
NumRows());
   163           if (!gselect_reader.HasKey(utt) ||
   164               gselect_reader.Value(utt).size() != feats.
NumRows()) {
   165             KALDI_WARN << 
"No Gaussian-selection info available for utterance "   166                        << utt << 
" (or wrong size)";
   170           const std::vector<std::vector<int32> > &gselect =
   171               gselect_reader.Value(utt);
   174                                  gselect, &spk_vars, &spk_stats);
   183           spk_stats.Update(am_sgmm, min_count, &spk_vec, &impr, &spk_tot_t);
   184           vecs_writer.Write(spk, spk_vec);
   186         KALDI_LOG << 
"For speaker " << spk << 
", auxf-impr from speaker vector is "   187                   << (impr/spk_tot_t) << 
", over " << spk_tot_t << 
" frames.";
   193       for (; !feature_reader.Done(); feature_reader.Next()) {
   194         string utt = feature_reader.Key();        
   196         if (!post_reader.HasKey(utt) ||
   197             post_reader.Value(utt).size() != feats.
NumRows()) {
   198           KALDI_WARN << 
"Did not find posts for utterance "   199                      << utt << 
" (or wrong size).";
   203         const Posterior &post = post_reader.Value(utt);
   206         if (spkvecs_reader.IsOpen()) {
   207           if (spkvecs_reader.HasKey(utt)) {
   211             KALDI_WARN << 
"Cannot find speaker vector for utterance " << utt
   212                        << 
", not processing it.";
   220         if (!gselect_reader.HasKey(utt) ||
   221             gselect_reader.Value(utt).size() != feats.
NumRows()) {
   222           KALDI_WARN << 
"No Gaussian-selection info available for utterance "   223                      << utt << 
" (or wrong size)";
   227         const std::vector<std::vector<int32> > &gselect =
   228             gselect_reader.Value(utt);
   233                                gselect, &spk_vars, &spk_stats);
   240           spk_stats.Update(am_sgmm, min_count, &spk_vec, &impr, &utt_tot_t);
   241           vecs_writer.Write(utt, spk_vec);
   243         KALDI_LOG << 
"For utterance " << utt << 
", auxf-impr from speaker vectors is "   244                   << (impr/utt_tot_t) << 
", over " << utt_tot_t << 
" frames.";
   250     KALDI_LOG << 
"Overall auxf impr per frame is "   251               << (tot_impr / tot_t) << 
" over " << tot_t << 
" frames.";
   252     KALDI_LOG << 
"Done " << num_done << 
" files, " << num_err << 
" with errors.";
   253     return (num_done != 0 ? 0 : 1);
   254   } 
catch(
const std::exception &e) {
   255     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 the accumulators required to update the speaker vectors v_s. 
 
const Vector< BaseFloat > & GetSpeakerVector()
 
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 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...
 
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size). 
 
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)
 
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
 
A class representing a vector. 
 
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix). 
 
void SetSpeakerVector(const Vector< BaseFloat > &v_s_in)
 
int32 SpkSpaceDim() const