29 int main(
int argc,
char *argv[]) {
31 using namespace kaldi;
34 "Print out per-frame log-likelihoods for each utterance, as an archive\n" 35 "of vectors of floats. If --average=true, prints out the average per-frame\n" 36 "log-likelihood for each utterance, as a single float.\n" 37 "Usage: gmm-global-get-frame-likes [options] <model-in> <feature-rspecifier> " 38 "<likes-out-wspecifier>\n" 39 "e.g.: gmm-global-get-frame-likes 1.mdl scp:train.scp ark:1.likes\n";
43 std::string gselect_rspecifier;
44 po.
Register(
"gselect", &gselect_rspecifier,
"rspecifier for gselect objects " 45 "to limit the #Gaussians accessed on each frame.");
46 po.
Register(
"average", &average,
"If true, print out the average per-frame " 47 "log-likelihood as a single float per utterance.");
55 std::string model_filename = po.
GetArg(1),
56 feature_rspecifier = po.
GetArg(2),
57 likes_wspecifier = po.
GetArg(3);
62 Input ki(model_filename, &binary_read);
66 double tot_like = 0.0, tot_frames = 0.0;
72 int32 num_done = 0, num_err = 0;
74 for (; !feature_reader.
Done(); feature_reader.
Next()) {
75 std::string key = feature_reader.
Key();
80 if (gselect_rspecifier !=
"") {
81 if (!gselect_reader.
HasKey(key)) {
82 KALDI_WARN <<
"No gselect information for utterance " << key;
86 const std::vector<std::vector<int32> > &gselect =
87 gselect_reader.
Value(key);
88 if (gselect.size() !=
static_cast<size_t>(file_frames)) {
89 KALDI_WARN <<
"gselect information for utterance " << key
90 <<
" has wrong size " << gselect.size() <<
" vs. " 96 for (
int32 i = 0;
i < file_frames;
i++) {
98 const std::vector<int32> &this_gselect = gselect[
i];
99 int32 gselect_size = this_gselect.size();
106 for (
int32 i = 0;
i < file_frames;
i++)
110 tot_like += likes.
Sum();
111 tot_frames += file_frames;
113 average_likes_writer.
Write(key, likes.
Sum() / file_frames);
115 likes_writer.
Write(key, likes);
118 KALDI_LOG <<
"Done " << num_done <<
" files; " << num_err
121 <<
"frame = " << (tot_like/tot_frames) <<
" over " << tot_frames
123 return (num_done != 0 ? 0 : 1);
124 }
catch(
const std::exception &e) {
125 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void LogLikelihoodsPreselect(const VectorBase< BaseFloat > &data, const std::vector< int32 > &indices, Vector< BaseFloat > *loglikes) const
Outputs the per-component log-likelihoods of a subset of mixture components.
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
Real LogSumExp(Real prune=-1.0) const
Returns log(sum(exp())) without exp overflow If prune > 0.0, ignores terms less than the max - prune...
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...
int main(int argc, char *argv[])
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)
BaseFloat LogLikelihood(const VectorBase< BaseFloat > &data) const
Returns the log-likelihood of a data point (vector) given the GMM.
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)
Real Sum() const
Returns sum of the elements.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void Read(std::istream &in, bool binary)
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition for Gaussian Mixture Model with diagonal covariances.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...