54 using namespace kaldi;
56 "Estimate linear-VTLN transforms, either per utterance or for " 57 "the supplied set of speakers (spk2utt option). Reads posteriors. \n" 58 "Usage: gmm-est-lvtln-trans [options] <model-in> <lvtln-in> " 59 "<feature-rspecifier> <gpost-rspecifier> <lvtln-trans-wspecifier> [<warp-wspecifier>]\n";
62 string spk2utt_rspecifier;
64 std::string norm_type =
"offset";
65 po.Register(
"norm-type", &norm_type,
"type of fMLLR applied (\"offset\"|\"none\"|\"diag\")");
66 po.Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to " 67 "utterance-list map");
68 po.Register(
"logdet-scale", &logdet_scale,
"Scale on log-determinant term in auxiliary function");
72 if (po.NumArgs() < 5 || po.NumArgs() > 6) {
78 model_rxfilename = po.GetArg(1),
79 lvtln_rxfilename = po.GetArg(2),
80 feature_rspecifier = po.GetArg(3),
81 gpost_rspecifier = po.GetArg(4),
82 trans_wspecifier = po.GetArg(5),
83 warp_wspecifier = po.GetOptArg(6);
88 Input ki(model_rxfilename, &binary);
90 trans_model.
Read(ki.Stream(), binary);
91 am_gmm.
Read(ki.Stream(), binary);
99 double tot_lvtln_impr = 0.0, tot_t = 0.0;
105 std::vector<int32> class_counts(lvtln.
NumClasses(), 0);
106 int32 num_done = 0, num_no_gpost = 0, num_other_error = 0;
107 if (spk2utt_rspecifier !=
"") {
111 for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
113 string spk = spk2utt_reader.Key();
114 const vector<string> &uttlist = spk2utt_reader.Value();
115 for (
size_t i = 0;
i < uttlist.size();
i++) {
116 std::string utt = uttlist[
i];
117 if (!feature_reader.HasKey(utt)) {
118 KALDI_WARN <<
"Did not find features for utterance " << utt;
121 if (!gpost_reader.HasKey(utt)) {
122 KALDI_WARN <<
"Did not find posteriors for utterance " << utt;
127 const GaussPost &gpost = gpost_reader.Value(utt);
128 if (static_cast<int32>(gpost.size()) != feats.
NumRows()) {
129 KALDI_WARN <<
"GauPost vector has wrong size " << gpost.size()
152 class_counts[class_idx]++;
153 transform_writer.Write(spk, transform);
154 if (warp_wspecifier !=
"")
155 warp_writer.Write(spk, lvtln.
GetWarp(class_idx));
157 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from LVTLN is " 158 << (impr/spk_tot_t) <<
", over " << spk_tot_t <<
" frames.";
159 tot_lvtln_impr += impr;
164 for (; !feature_reader.Done(); feature_reader.Next()) {
165 string utt = feature_reader.Key();
166 if (!gpost_reader.HasKey(utt)) {
167 KALDI_WARN <<
"Did not find gposts for utterance " 173 const GaussPost &gpost = gpost_reader.Value(utt);
175 if (static_cast<int32>(gpost.size()) != feats.
NumRows()) {
176 KALDI_WARN <<
"GauPost has wrong size " << gpost.size()
187 BaseFloat impr, utt_tot_t = spk_stats.beta_;
199 class_counts[class_idx]++;
200 transform_writer.Write(utt, transform);
201 if (warp_wspecifier !=
"")
202 warp_writer.Write(utt, lvtln.
GetWarp(class_idx));
205 KALDI_LOG <<
"For utterance " << utt <<
", auxf-impr from LVTLN is " 206 << (impr/utt_tot_t) <<
", over " << utt_tot_t <<
" frames.";
207 tot_lvtln_impr += impr;
213 std::ostringstream s;
214 for (
size_t i = 0;
i < class_counts.size();
i++)
215 s <<
' ' << class_counts[
i];
216 KALDI_LOG <<
"Distribution of classes is: " << s.str();
219 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_gpost
220 <<
" with no gposts, " << num_other_error <<
" with other errors.";
221 KALDI_LOG <<
"Overall LVTLN auxf impr per frame is " 222 << (tot_lvtln_impr / tot_t) <<
" over " << tot_t <<
" frames.";
223 return (num_done == 0 ? 1 : 0);
224 }
catch(
const std::exception &e) {
225 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...
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.
void Read(std::istream &is, bool binary)
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).
std::vector< std::vector< std::pair< int32, Vector< BaseFloat > > > > GaussPost
GaussPost is a typedef for storing Gaussian-level posteriors for an utterance.
void Read(std::istream &in_stream, bool binary)