27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
32 typedef kaldi::int64 int64;
35 "Computes and prints the average log-prob per frame of the given data with a\n" 36 "neural net. The input of this is the output of e.g. nnet-get-egs\n" 37 "Aside from the logging output, which goes to the standard error, this program\n" 38 "prints the average log-prob per frame to the standard output.\n" 39 "Also see nnet-logprob, which produces a matrix of log-probs for each utterance.\n" 41 "Usage: nnet-compute-prob [options] <model-in> <training-examples-in>\n" 42 "e.g.: nnet-compute-prob 1.nnet ark:valid.egs\n";
53 std::string nnet_rxfilename = po.
GetArg(1),
54 examples_rspecifier = po.
GetArg(2);
60 Input ki(nnet_rxfilename, &binary_read);
66 std::vector<NnetExample> examples;
67 double tot_weight = 0.0, tot_like = 0.0, tot_accuracy = 0.0;
68 int64 num_examples = 0;
70 for (; !example_reader.
Done(); example_reader.
Next(), num_examples++) {
71 if (examples.size() == 1000) {
74 tot_accuracy += accuracy;
78 examples.push_back(example_reader.
Value());
79 if (num_examples % 5000 == 0 && num_examples > 0)
80 KALDI_LOG <<
"Saw " << num_examples <<
" examples, average " 81 <<
"probability is " << (tot_like / num_examples) <<
" with " 82 <<
"total weight " << num_examples;
84 if (!examples.empty()) {
87 tot_accuracy += accuracy;
91 KALDI_LOG <<
"Saw " << num_examples <<
" examples, average " 92 <<
"probability is " << (tot_like / tot_weight)
93 <<
" and accuracy is " << (tot_accuracy / tot_weight) <<
" with " 94 <<
"total weight " << tot_weight;
96 std::cout << (tot_like / tot_weight) <<
"\n";
97 return (num_examples == 0 ? 1 : 0);
98 }
catch(
const std::exception &e) {
99 std::cerr << e.what() <<
'\n';
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 Read(std::istream &is, bool binary)
double ComputeNnetObjf(const Nnet &nnet, const std::vector< NnetExample > &examples, double *tot_accuracy)
Computes objective function over a minibatch.
int main(int argc, char *argv[])
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
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.
BaseFloat TotalNnetTrainingWeight(const std::vector< NnetExample > &egs)
Returns the total weight summed over all the examples...
int NumArgs() const
Number of positional parameters (c.f. argc-1).
const Nnet & GetNnet() const