41 for (
size_t i = 0;
i < gpost.size();
i++) {
43 gpost[
i].gselect, *spk_vars,
46 for (
size_t j = 0;
j < gpost[
i].tids.size();
j++) {
49 gpost[
i].posteriors[j], pdf_id,
57 int main(
int argc,
char *argv[]) {
60 using namespace kaldi;
62 "Estimate SGMM speaker vectors, either per utterance or for the " 63 "supplied set of speakers (with spk2utt option).\n" 64 "Reads Gaussian-level posteriors. Writes to a table of vectors.\n" 65 "Usage: sgmm2-est-spkvecs-gpost [options] <model-in> <feature-rspecifier> " 66 "<gpost-rspecifier> <vecs-wspecifier>\n";
69 string spk2utt_rspecifier, spkvecs_rspecifier;
73 po.
Register(
"spk2utt", &spk2utt_rspecifier,
74 "File to read speaker to utterance-list map from.");
75 po.
Register(
"spkvec-min-count", &min_count,
76 "Minimum count needed to estimate speaker vectors");
77 po.
Register(
"rand-prune", &rand_prune,
"Randomized pruning parameter for posteriors (more->faster).");
78 po.
Register(
"spk-vecs", &spkvecs_rspecifier,
"Speaker vectors to use during aligment (rspecifier)");
86 string model_rxfilename = po.
GetArg(1),
87 feature_rspecifier = po.
GetArg(2),
88 gpost_rspecifier = po.
GetArg(3),
89 vecs_wspecifier = po.
GetArg(4);
95 Input ki(model_rxfilename, &binary);
107 double tot_impr = 0.0, tot_t = 0.0;
108 int32 num_done = 0, num_err = 0;
110 if (!spk2utt_rspecifier.empty()) {
114 for (; !spk2utt_reader.
Done(); spk2utt_reader.
Next()) {
116 string spk = spk2utt_reader.
Key();
117 const vector<string> &uttlist = spk2utt_reader.
Value();
120 if (spkvecs_reader.
IsOpen()) {
121 if (spkvecs_reader.
HasKey(spk)) {
125 KALDI_WARN <<
"Cannot find speaker vector for " << spk;
129 for (
size_t i = 0;
i < uttlist.size();
i++) {
130 std::string utt = uttlist[
i];
131 if (!feature_reader.
HasKey(utt)) {
132 KALDI_WARN <<
"Did not find features for utterance " << utt;
136 if (!gpost_reader.
HasKey(utt) ||
138 KALDI_WARN <<
"Did not find posteriors for utterance " << utt
139 <<
" (or wrong size).";
146 &spk_vars, &spk_stats);
155 spk_stats.
Update(am_sgmm, min_count, &spk_vec, &impr, &spk_tot_t);
156 vecs_writer.
Write(spk, spk_vec);
158 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from speaker vector is " 159 << (impr/spk_tot_t) <<
", over " << spk_tot_t <<
" frames.\n";
165 for (; !feature_reader.
Done(); feature_reader.
Next()) {
166 string utt = feature_reader.
Key();
168 if (!gpost_reader.
HasKey(utt) ||
170 KALDI_WARN <<
"Did not find posts for utterance " 178 if (spkvecs_reader.
IsOpen()) {
179 if (spkvecs_reader.
HasKey(utt)) {
183 KALDI_WARN <<
"Cannot find speaker vector for " << utt;
191 &spk_vars, &spk_stats);
198 spk_stats.
Update(am_sgmm, min_count, &spk_vec, &impr, &utt_tot_t);
199 vecs_writer.
Write(utt, spk_vec);
201 KALDI_LOG <<
"For utterance " << utt <<
", auxf-impr from speaker vectors is " 202 << (impr/utt_tot_t) <<
", over " << utt_tot_t <<
" frames.";
208 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_err
210 KALDI_LOG <<
"Overall auxf impr per frame is " << (tot_impr / tot_t)
211 <<
" over " << tot_t <<
" frames.";
212 return (num_done != 0 ? 0 : 1);
213 }
catch(
const std::exception &e) {
214 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.
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
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...
int32 TransitionIdToPdf(int32 trans_id) const
void ComputePerSpkDerivedVars(Sgmm2PerSpkDerivedVars *vars) const
Computes the per-speaker derived vars; assumes vars->v_s is already set up.
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...
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
BaseFloat AccumulateFromPosteriors(const AmSgmm2 &model, const Sgmm2PerFrameDerivedVars &frame_vars, const Matrix< BaseFloat > &posteriors, int32 pdf_index, Sgmm2PerSpkDerivedVars *spk_vars)
Accumulate statistics, given posteriors.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
const T & Value(const std::string &key)
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Update(const AmSgmm2 &model, BaseFloat min_count, Vector< BaseFloat > *v_s, BaseFloat *objf_impr_out, BaseFloat *count_out)
Update speaker vector.
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)
void Clear()
Clear the statistics.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
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
Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf...
int main(int argc, char *argv[])