nnet3-compute-prob.cc File Reference
Include dependency graph for nnet3-compute-prob.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 26 of file nnet3-compute-prob.cc.

References kaldi::nnet3::CollapseModel(), NnetComputeProb::Compute(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), NnetComputeProb::PrintTotalStats(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), NnetComputeProbOptions::Register(), kaldi::nnet3::SetBatchnormTestMode(), kaldi::nnet3::SetDropoutTestMode(), and SequentialTableReader< Holder >::Value().

26  {
27  try {
28  using namespace kaldi;
29  using namespace kaldi::nnet3;
30  typedef kaldi::int32 int32;
31  typedef kaldi::int64 int64;
32 
33  const char *usage =
34  "Computes and prints in logging messages the average log-prob per frame of\n"
35  "the given data with an nnet3 neural net. The input of this is the output of\n"
36  "e.g. nnet3-get-egs | nnet3-merge-egs.\n"
37  "\n"
38  "Usage: nnet3-compute-prob [options] <raw-model-in> <training-examples-in>\n"
39  "e.g.: nnet3-compute-prob 0.raw ark:valid.egs\n";
40 
41 
42  bool batchnorm_test_mode = true, dropout_test_mode = true,
43  collapse_model = true;
44 
45  // This program doesn't support using a GPU, because these probabilities are
46  // used for diagnostics, and you can just compute them with a small enough
47  // amount of data that a CPU can do it within reasonable time.
48 
50 
51  ParseOptions po(usage);
52 
53  po.Register("batchnorm-test-mode", &batchnorm_test_mode,
54  "If true, set test-mode to true on any BatchNormComponents.");
55  po.Register("dropout-test-mode", &dropout_test_mode,
56  "If true, set test-mode to true on any DropoutComponents and "
57  "DropoutMaskComponents.");
58  po.Register("collapse-model", &collapse_model,
59  "If true, collapse model to the extent possible before "
60  "using it (for efficiency).");
61 
62  opts.Register(&po);
63 
64  po.Read(argc, argv);
65 
66  if (po.NumArgs() != 2) {
67  po.PrintUsage();
68  exit(1);
69  }
70 
71  std::string raw_nnet_rxfilename = po.GetArg(1),
72  examples_rspecifier = po.GetArg(2);
73 
74  Nnet nnet;
75  ReadKaldiObject(raw_nnet_rxfilename, &nnet);
76 
77  if (batchnorm_test_mode)
78  SetBatchnormTestMode(true, &nnet);
79 
80  if (dropout_test_mode)
81  SetDropoutTestMode(true, &nnet);
82 
83  if (collapse_model)
85 
86  NnetComputeProb prob_computer(opts, nnet);
87 
88  SequentialNnetExampleReader example_reader(examples_rspecifier);
89 
90  for (; !example_reader.Done(); example_reader.Next())
91  prob_computer.Compute(example_reader.Value());
92 
93  bool ok = prob_computer.PrintTotalStats();
94 
95  return (ok ? 0 : 1);
96  } catch(const std::exception &e) {
97  std::cerr << e.what() << '\n';
98  return -1;
99  }
100 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void CollapseModel(const CollapseModelConfig &config, Nnet *nnet)
This function modifies the neural net for efficiency, in a way that suitable to be done in test time...
Definition: nnet-utils.cc:2100
void SetBatchnormTestMode(bool test_mode, Nnet *nnet)
This function affects only components of type BatchNormComponent.
Definition: nnet-utils.cc:564
kaldi::int32 int32
This class is for computing cross-entropy and accuracy values in a neural network, for diagnostics.
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
void SetDropoutTestMode(bool test_mode, Nnet *nnet)
This function affects components of child-classes of RandomComponent.
Definition: nnet-utils.cc:573
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
Config class for the CollapseModel function.
Definition: nnet-utils.h:240