60 using namespace kaldi;
62 "Estimate linear-VTLN transforms, either per utterance or for " 63 "the supplied set of speakers (spk2utt option); this version\n" 64 "is for a global diagonal GMM (also known as a UBM). Reads posteriors\n" 65 "indicating Gaussian indexes in the UBM.\n" 67 "Usage: gmm-global-est-lvtln-trans [options] <gmm-in> <lvtln-in> " 68 "<feature-rspecifier> <gpost-rspecifier> <lvtln-trans-wspecifier> [<warp-wspecifier>]\n" 69 "e.g.: gmm-global-est-lvtln-trans 0.ubm 0.lvtln '$feats' ark,s,cs:- ark:1.trans ark:1.warp\n" 70 "(where the <gpost-rspecifier> will likely come from gmm-global-get-post or\n" 71 "gmm-global-gselect-to-post\n";
74 string spk2utt_rspecifier;
76 std::string norm_type =
"offset";
77 po.Register(
"norm-type", &norm_type,
"type of fMLLR applied (\"offset\"|\"none\"|\"diag\")");
78 po.Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to " 79 "utterance-list map");
80 po.Register(
"logdet-scale", &logdet_scale,
"Scale on log-determinant term in auxiliary function");
84 if (po.NumArgs() < 5 || po.NumArgs() > 6) {
90 model_rxfilename = po.GetArg(1),
91 lvtln_rxfilename = po.GetArg(2),
92 feature_rspecifier = po.GetArg(3),
93 post_rspecifier = po.GetArg(4),
94 trans_wspecifier = po.GetArg(5),
95 warp_wspecifier = po.GetOptArg(6);
105 double tot_lvtln_impr = 0.0, tot_t = 0.0;
111 std::vector<int32> class_counts(lvtln.
NumClasses(), 0);
112 int32 num_done = 0, num_no_post = 0, num_other_error = 0;
113 if (spk2utt_rspecifier !=
"") {
117 for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
119 string spk = spk2utt_reader.Key();
120 const vector<string> &uttlist = spk2utt_reader.Value();
121 for (
size_t i = 0;
i < uttlist.size();
i++) {
122 std::string utt = uttlist[
i];
123 if (!feature_reader.HasKey(utt)) {
124 KALDI_WARN <<
"Did not find features for utterance " << utt;
127 if (!post_reader.HasKey(utt)) {
128 KALDI_WARN <<
"Did not find posteriors for utterance " << utt;
133 const Posterior &post = post_reader.Value(utt);
134 if (static_cast<int32>(post.size()) != feats.
NumRows()) {
135 KALDI_WARN <<
"Posterior vector has wrong size " << post.size()
158 class_counts[class_idx]++;
159 transform_writer.Write(spk, transform);
160 if (warp_wspecifier !=
"")
161 warp_writer.Write(spk, lvtln.
GetWarp(class_idx));
163 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from LVTLN is " 164 << (impr/spk_tot_t) <<
", over " << spk_tot_t <<
" frames.";
165 tot_lvtln_impr += impr;
170 for (; !feature_reader.Done(); feature_reader.Next()) {
171 string utt = feature_reader.Key();
172 if (!post_reader.HasKey(utt)) {
173 KALDI_WARN <<
"Did not find posterior for utterance " 179 const Posterior &post = post_reader.Value(utt);
181 if (static_cast<int32>(post.size()) != feats.
NumRows()) {
182 KALDI_WARN <<
"Posterior has wrong size " << post.size()
193 BaseFloat impr, utt_tot_t = spk_stats.beta_;
205 class_counts[class_idx]++;
206 transform_writer.Write(utt, transform);
207 if (warp_wspecifier !=
"")
208 warp_writer.Write(utt, lvtln.
GetWarp(class_idx));
211 KALDI_LOG <<
"For utterance " << utt <<
", auxf-impr from LVTLN is " 212 << (impr/utt_tot_t) <<
", over " << utt_tot_t <<
" frames.";
213 tot_lvtln_impr += impr;
219 std::ostringstream s;
220 for (
size_t i = 0;
i < class_counts.size();
i++)
221 s <<
' ' << class_counts[
i];
222 KALDI_LOG <<
"Distribution of classes is: " << s.str();
225 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_post
226 <<
" with no posteriors, " << num_other_error <<
" with other errors.";
227 KALDI_LOG <<
"Overall LVTLN auxf impr per frame is " 228 << (tot_lvtln_impr / tot_t) <<
" over " << tot_t <<
" frames.";
229 return (num_done == 0 ? 1 : 0);
230 }
catch(
const std::exception &e) {
231 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
BaseFloat GetWarp(int32 i) const
This does not work with multiple feature transforms.
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 ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
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 ComputeTransform(const FmllrDiagGmmAccs &accs, std::string norm_type, BaseFloat logdet_scale, MatrixBase< BaseFloat > *Ws, int32 *class_idx, BaseFloat *logdet_out, BaseFloat *objf_impr=NULL, BaseFloat *count=NULL)
Compute the transform for the speaker.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition for Gaussian Mixture Model with diagonal covariances.