38 for (
size_t i = 0;
i < gpost.size();
i++) {
39 for (
size_t j = 0;
j < gpost[
i].size();
j++) {
40 int32 pdf_id = gpost[
i][
j].first;
43 feats.
Row(
i), posterior);
51 int main(
int argc,
char *argv[]) {
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");
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),
88 Input ki(model_rxfilename, &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;
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 !=
"")
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 " 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 !=
"")
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
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
This does not work with multiple feature transforms.
void AccumulateFromPosteriors(const DiagGmm &gmm, const VectorBase< BaseFloat > &data, const VectorBase< BaseFloat > &posteriors)
Accumulate stats for a GMM, given supplied posteriors.
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 Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
const T & Value(const std::string &key)
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...
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).
DiagGmm & GetPdf(int32 pdf_index)
Accessors.
A class representing a vector.
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)
std::string GetOptArg(int param) const
int main(int argc, char *argv[])