36 using namespace kaldi;
38 "Compute FMLLR transforms per-utterance (default) or per-speaker for " 39 "the supplied set of speakers (spk2utt option). Note: writes RegtreeFmllrDiagGmm objects\n" 40 "Usage: gmm-est-regtree-fmllr [options] <model-in> <feature-rspecifier> " 41 "<posteriors-rspecifier> <regression-tree> <transforms-wspecifier>\n";
44 string spk2utt_rspecifier;
46 po.Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to " 47 "utterance-list map");
48 po.Register(
"binary", &binary,
"Write output in binary mode");
55 if (po.NumArgs() != 5) {
60 string model_filename = po.GetArg(1),
61 feature_rspecifier = po.GetArg(2),
62 posteriors_rspecifier = po.GetArg(3),
63 regtree_filename = po.GetArg(4),
64 xforms_wspecifier = po.GetArg(5);
73 Input ki(model_filename, &binary);
74 trans_model.
Read(ki.Stream(), binary);
75 am_gmm.
Read(ki.Stream(), binary);
80 Input in(regtree_filename, &binary);
81 regtree.
Read(in.Stream(), binary, am_gmm);
88 double tot_like = 0.0, tot_t = 0;
90 int32 num_done = 0, num_no_posterior = 0, num_other_error = 0;
91 double tot_objf_impr = 0.0, tot_t_objf = 0.0;
92 if (spk2utt_rspecifier !=
"") {
95 for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
96 string spk = spk2utt_reader.Key();
98 const vector<string> &uttlist = spk2utt_reader.Value();
99 for (vector<string>::const_iterator utt_itr = uttlist.begin(),
100 itr_end = uttlist.end(); utt_itr != itr_end; ++utt_itr) {
101 if (!feature_reader.HasKey(*utt_itr)) {
102 KALDI_WARN <<
"Did not find features for utterance " << *utt_itr;
105 if (!posteriors_reader.HasKey(*utt_itr)) {
106 KALDI_WARN <<
"Did not find posteriors for utterance " 112 const Posterior &posterior = posteriors_reader.Value(*utt_itr);
113 if (static_cast<int32>(posterior.size()) != feats.
NumRows()) {
114 KALDI_WARN <<
"Posteriors has wrong size " << (posterior.size())
115 <<
" vs. " << (feats.
NumRows());
123 for (
size_t i = 0;
i < posterior.size();
i++) {
124 for (
size_t j = 0;
j < pdf_posterior[
i].size();
j++) {
125 int32 pdf_id = pdf_posterior[
i][
j].first;
128 feats.
Row(
i), pdf_id,
133 KALDI_VLOG(2) <<
"Average like for this file is " << (file_like/file_t)
134 <<
" over " << file_t <<
" frames.";
135 tot_like += file_like;
138 if (num_done % 10 == 0)
139 KALDI_VLOG(1) <<
"Avg like per frame so far is " 140 << (tot_like / tot_t);
143 fmllr_accs.
Update(regtree, opts, &fmllr_xforms, &objf_impr, &t);
144 KALDI_LOG <<
"fMLLR objf improvement for speaker " << spk <<
" is " 145 << (objf_impr/(t+1.0e-10)) <<
" per frame over " << t
147 tot_objf_impr += objf_impr;
149 fmllr_writer.Write(spk, fmllr_xforms);
153 for (; !feature_reader.Done(); feature_reader.Next()) {
154 string key = feature_reader.Key();
155 if (!posteriors_reader.HasKey(key)) {
156 KALDI_WARN <<
"Did not find posteriors for utterance " 162 const Posterior &posterior = posteriors_reader.Value(key);
164 if (static_cast<int32>(posterior.size()) != feats.
NumRows()) {
165 KALDI_WARN <<
"Posteriors has wrong size " << (posterior.size())
166 <<
" vs. " << (feats.
NumRows());
176 for (
size_t i = 0;
i < posterior.size();
i++) {
177 for (
size_t j = 0;
j < pdf_posterior[
i].size();
j++) {
178 int32 pdf_id = pdf_posterior[
i][
j].first;
181 feats.
Row(
i), pdf_id,
186 KALDI_VLOG(2) <<
"Average like for this file is " << (file_like/file_t)
187 <<
" over " << file_t <<
" frames.";
188 tot_like += file_like;
190 if (num_done % 10 == 0)
191 KALDI_VLOG(1) <<
"Avg like per frame so far is " 192 << (tot_like / tot_t);
194 fmllr_accs.
Update(regtree, opts, &fmllr_xforms, &objf_impr, &t);
195 KALDI_LOG <<
"fMLLR objf improvement for utterance " << key <<
" is " 196 << (objf_impr/(t+1.0e-10)) <<
" per frame over " << t
198 tot_objf_impr += objf_impr;
200 fmllr_writer.Write(feature_reader.Key(), fmllr_xforms);
203 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_posterior
204 <<
" with no posteriors, " << num_other_error
205 <<
" with other errors.";
206 KALDI_LOG <<
"Overall objf improvement from MLLR is " << (tot_objf_impr/tot_t_objf)
207 <<
" per frame " <<
" over " << tot_t_objf <<
" frames.";
208 KALDI_LOG <<
"Overall acoustic likelihood was " << (tot_like/tot_t)
209 <<
" over " << tot_t <<
" frames.";
211 }
catch(
const std::exception &e) {
212 std::cerr << e.what();
void Read(std::istream &in, bool binary, const AmDiagGmm &am)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Register(OptionsItf *opts)
A templated class for writing objects to an archive or script file; see The Table concept...
Allows random access to a collection of objects in an archive or script file; see The Table concept...
An FMLLR (feature-space MLLR) transformation, also called CMLLR (constrained MLLR) is an affine trans...
int32 NumBaseclasses() const
Accessors (const)
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...
Configuration variables for FMLLR transforms.
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
A regression tree is a clustering of Gaussian densities in an acoustic model, such that the group of ...
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).
Class for computing the accumulators needed for the maximum-likelihood estimate of FMLLR transforms f...
BaseFloat AccumulateForGmm(const RegressionTree ®tree, const AmDiagGmm &am, const VectorBase< BaseFloat > &data, size_t pdf_index, BaseFloat weight)
Accumulate stats for a single GMM in the model; returns log likelihood.
void Update(const RegressionTree ®tree, const RegtreeFmllrOptions &opts, RegtreeFmllrDiagGmm *out_fmllr, BaseFloat *auxf_impr, BaseFloat *tot_t) const
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.
void Init(size_t num_bclass, size_t dim)
void Read(std::istream &in_stream, bool binary)