31 int main(
int argc,
char *argv[]) {
34 using namespace kaldi;
36 "Compute FMLLR transforms per-utterance (default) or per-speaker for " 37 "the supplied set of speakers (spk2utt option). Note: writes RegtreeFmllrDiagGmm objects\n" 38 "Usage: gmm-est-regtree-fmllr-ali [options] <model-in> <feature-rspecifier> " 39 "<alignments-rspecifier> <regression-tree> <transforms-wspecifier>\n";
42 string spk2utt_rspecifier;
44 po.
Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to " 45 "utterance-list map");
46 po.
Register(
"binary", &binary,
"Write output in binary mode");
58 string model_filename = po.
GetArg(1),
59 feature_rspecifier = po.
GetArg(2),
60 alignments_rspecifier = po.
GetArg(3),
61 regtree_filename = po.
GetArg(4),
62 xforms_wspecifier = po.
GetArg(5);
71 Input ki(model_filename, &binary);
78 Input in(regtree_filename, &binary);
86 double tot_like = 0.0;
87 kaldi::int64 tot_t = 0;
89 int32 num_done = 0, num_no_alignment = 0, num_other_error = 0;
90 double tot_objf_impr = 0.0, tot_t_objf = 0.0;
91 if (spk2utt_rspecifier !=
"") {
94 for (; !spk2utt_reader.
Done(); spk2utt_reader.
Next()) {
95 string spk = spk2utt_reader.
Key();
97 const vector<string> &uttlist = spk2utt_reader.
Value();
98 for (vector<string>::const_iterator utt_itr = uttlist.begin(),
99 itr_end = uttlist.end(); utt_itr != itr_end; ++utt_itr) {
100 if (!feature_reader.
HasKey(*utt_itr)) {
101 KALDI_WARN <<
"Did not find features for utterance " << *utt_itr;
104 if (!alignments_reader.
HasKey(*utt_itr)) {
105 KALDI_WARN <<
"Did not find aligned transcription for utterance " 111 const vector<int32> &alignment = alignments_reader.
Value(*utt_itr);
112 if (static_cast<int32>(alignment.size()) != feats.
NumRows()) {
113 KALDI_WARN <<
"Alignments has wrong size " << (alignment.size())
114 <<
" vs. " << (feats.
NumRows());
120 for (
size_t i = 0;
i < alignment.size();
i++) {
123 feats.
Row(i), pdf_id, 1.0);
125 KALDI_VLOG(2) <<
"Average like for this file is " << (file_like
126 / alignment.size()) <<
" over " << alignment.size()
128 tot_like += file_like;
129 tot_t += alignment.size();
132 <<
"Avg like per frame so far is " << (tot_like / tot_t) <<
'\n';
135 fmllr_accs.
Update(regtree, opts, &fmllr_xforms, &objf_impr, &t);
136 KALDI_LOG <<
"fMLLR objf improvement for speaker " << spk <<
" is " 137 << (objf_impr/(t+1.0e-10)) <<
" per frame over " << t
139 tot_objf_impr += objf_impr;
141 fmllr_writer.
Write(spk, fmllr_xforms);
145 for (; !feature_reader.
Done(); feature_reader.
Next()) {
146 string key = feature_reader.
Key();
147 if (!alignments_reader.
HasKey(key)) {
148 KALDI_WARN <<
"Did not find aligned transcription for utterance " 154 const vector<int32> &alignment = alignments_reader.
Value(key);
156 if (static_cast<int32>(alignment.size()) != feats.
NumRows()) {
157 KALDI_WARN <<
"Alignments has wrong size " << (alignment.size())
158 <<
" vs. " << (feats.
NumRows());
166 for (
size_t i = 0;
i < alignment.size();
i++) {
169 feats.
Row(i), pdf_id, 1.0);
171 KALDI_VLOG(2) <<
"Average like for this file is " << (file_like
172 / alignment.size()) <<
" over " << alignment.size() <<
" frames.";
173 tot_like += file_like;
174 tot_t += alignment.size();
176 <<
"Avg like per frame so far is " << (tot_like / tot_t);
178 fmllr_accs.
Update(regtree, opts, &fmllr_xforms, &objf_impr, &t);
179 KALDI_LOG <<
"fMLLR objf improvement for utterance " << key <<
" is " 180 << (objf_impr/(t+1.0e-10)) <<
" per frame over " << t
182 tot_objf_impr += objf_impr;
184 fmllr_writer.
Write(feature_reader.
Key(), fmllr_xforms);
188 KALDI_LOG <<
"Overall objf improvement from fMLLR is " 189 << (tot_objf_impr/tot_t_objf)
190 <<
" per frame over " << tot_t_objf <<
" frames.";
191 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_no_alignment
192 <<
" with no alignments, " << num_other_error
193 <<
" with other errors.";
194 KALDI_LOG <<
"Overall acoustic like per frame = " << (tot_like / tot_t)
195 <<
" over " << tot_t <<
" frames.";
197 }
catch(
const std::exception &e) {
198 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 PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Register(OptionsItf *opts)
A templated class for writing objects to an archive or script file; see The Table concept...
int32 TransitionIdToPdf(int32 trans_id) const
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...
An FMLLR (feature-space MLLR) transformation, also called CMLLR (constrained MLLR) is an affine trans...
int32 NumBaseclasses() const
Accessors (const)
int main(int argc, char *argv[])
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].
const T & Value(const std::string &key)
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...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
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)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
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 Init(size_t num_bclass, size_t dim)
void Read(std::istream &in_stream, bool binary)