29 using namespace kaldi;
33 "Precompute Gaussian indices for pruning\n" 34 " (e.g. in training UBMs, SGMMs, tied-mixture systems)\n" 35 " For each frame, gives a list of the n best Gaussian indices,\n" 36 " sorted from best to worst.\n" 37 "See also: gmm-global-get-post, fgmm-global-gselect-to-post,\n" 38 "copy-gselect, fgmm-gselect\n" 39 "Usage: gmm-gselect [options] <model-in> <feature-rspecifier> <gselect-wspecifier>\n" 40 "The --gselect option (which takes an rspecifier) limits selection to a subset\n" 42 "e.g.: gmm-gselect \"--gselect=ark:gunzip -c bigger.gselect.gz|\" --n=20 1.gmm \"ark:feature-command |\" \"ark,t:|gzip -c >gselect.1.gz\"\n";
45 int32 num_gselect = 50;
46 std::string gselect_rspecifier;
47 std::string likelihood_wspecifier;
48 po.Register(
"n", &num_gselect,
"Number of Gaussians to keep per frame\n");
49 po.Register(
"write-likes", &likelihood_wspecifier,
"rspecifier for likelihoods per " 51 po.Register(
"gselect", &gselect_rspecifier,
"rspecifier for gselect objects " 52 "to limit the search to");
55 if (po.NumArgs() != 3) {
60 std::string model_filename = po.GetArg(1),
61 feature_rspecifier = po.GetArg(2),
62 gselect_wspecifier = po.GetArg(3);
68 if (num_gselect > num_gauss) {
69 KALDI_WARN <<
"You asked for " << num_gselect <<
" Gaussians but GMM " 70 <<
"only has " << num_gauss <<
", returning this many. " 71 <<
"Note: this means the Gaussian selection is pointless.";
72 num_gselect = num_gauss;
75 double tot_like = 0.0;
76 kaldi::int64 tot_t = 0;
83 int32 num_done = 0, num_err = 0;
84 for (; !feature_reader.Done(); feature_reader.Next()) {
85 int32 tot_t_this_file = 0;
double tot_like_this_file = 0;
86 std::string utt = feature_reader.Key();
88 vector<vector<int32> > gselect(mat.
NumRows());
89 tot_t_this_file += mat.
NumRows();
90 if(gselect_rspecifier !=
"") {
91 if (!gselect_reader.HasKey(utt)) {
92 KALDI_WARN <<
"No gselect information for utterance " << utt;
96 const vector<vector<int32> > &preselect = gselect_reader.Value(utt);
97 if (preselect.size() !=
static_cast<size_t>(mat.
NumRows())) {
98 KALDI_WARN <<
"Input gselect for utterance " << utt <<
" has wrong size " 99 << preselect.size() <<
" vs. " << mat.
NumRows();
104 tot_like_this_file +=
106 num_gselect, &(gselect[
i]));
112 gselect_writer.Write(utt, gselect);
113 if (num_done % 10 == 0)
114 KALDI_LOG <<
"For " << num_done <<
"'th file, average UBM likelihood over " 115 << tot_t_this_file <<
" frames is " 116 << (tot_like_this_file/tot_t_this_file);
117 tot_t += tot_t_this_file;
118 tot_like += tot_like_this_file;
120 if(likelihood_wspecifier !=
"")
121 likelihood_writer.Write(utt, tot_like_this_file);
125 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_err
126 <<
" with errors, average UBM log-likelihood is " 127 << (tot_like/tot_t) <<
" over " << tot_t <<
" frames.";
129 if (num_done != 0)
return 0;
131 }
catch(
const std::exception &e) {
132 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
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...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int32 NumGauss() const
Returns the number of mixture components in the GMM.
BaseFloat GaussianSelectionPreselect(const VectorBase< BaseFloat > &data, const std::vector< int32 > &preselect, int32 num_gselect, std::vector< int32 > *output) const
Get gaussian selection information for one frame.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
BaseFloat GaussianSelection(const VectorBase< BaseFloat > &data, int32 num_gselect, std::vector< int32 > *output) const
Get gaussian selection information for one frame.
Definition for Gaussian Mixture Model with diagonal covariances.