40 const vector< vector<int32> > &gselect,
48 for (
size_t i = 0;
i < post.size();
i++) {
50 *spk_vars, &per_frame_vars);
52 for (
size_t j = 0;
j < pdf_post[
i].size();
j++) {
53 int32 pdf_id = pdf_post[
i][
j].first;
54 spk_stats->
Accumulate(am_sgmm, per_frame_vars, pdf_id,
55 pdf_post[
i][
j].second, spk_vars);
62 int main(
int argc,
char *argv[]) {
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)");
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);
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;
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) ||
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) ||
198 KALDI_WARN <<
"Did not find posts for utterance " 199 << utt <<
" (or wrong size).";
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) ||
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.
BaseFloat Accumulate(const AmSgmm2 &model, const Sgmm2PerFrameDerivedVars &frame_vars, int32 pdf_index, BaseFloat weight, Sgmm2PerSpkDerivedVars *spk_vars)
Accumulate statistics. Returns per-frame log-likelihood.
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...
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).
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...
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.
int main(int argc, char *argv[])
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.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void SetSpeakerVector(const Vector< BaseFloat > &v_s_in)
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.
int32 SpkSpaceDim() const
Holds the per-frame precomputed quantities x(t), x_{i}(t), z_{i}(t), and n_{i}(t) (cf...