nnet-am-info.cc File Reference
Include dependency graph for nnet-am-info.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 25 of file nnet-am-info.cc.

References ParseOptions::GetArg(), Nnet::GetLearningRates(), AmNnet::GetNnet(), rnnlm::i, AmNnet::Info(), KALDI_LOG, ParseOptions::NumArgs(), Nnet::NumUpdatableComponents(), ParseOptions::PrintUsage(), AmNnet::Read(), ParseOptions::Read(), TransitionModel::Read(), ParseOptions::Register(), and Input::Stream().

25  {
26  try {
27  using namespace kaldi;
28  using namespace kaldi::nnet2;
29  typedef kaldi::int32 int32;
30 
31  const char *usage =
32  "Print human-readable information about the neural network\n"
33  "acoustic model to the standard output\n"
34  "Usage: nnet-am-info [options] <nnet-in>\n"
35  "e.g.:\n"
36  " nnet-am-info 1.nnet\n";
37 
38  ParseOptions po(usage);
39 
40  bool print_learning_rates = false;
41 
42  po.Register("print-learning-rates", &print_learning_rates,
43  "If true, instead of printing the normal info, print a "
44  "colon-separated list of the learning rates for each updatable "
45  "layer, suitable to give to nnet-am-copy as the argument to"
46  "--learning-rates.");
47 
48  po.Read(argc, argv);
49 
50  if (po.NumArgs() != 1) {
51  po.PrintUsage();
52  exit(1);
53  }
54 
55  std::string nnet_rxfilename = po.GetArg(1);
56 
57  TransitionModel trans_model;
58  AmNnet am_nnet;
59  {
60  bool binary_read;
61  Input ki(nnet_rxfilename, &binary_read);
62  trans_model.Read(ki.Stream(), binary_read);
63  am_nnet.Read(ki.Stream(), binary_read);
64  }
65 
66  if (print_learning_rates) {
67  Vector<BaseFloat> learning_rates(am_nnet.GetNnet().NumUpdatableComponents());
68  am_nnet.GetNnet().GetLearningRates(&learning_rates);
69  int32 nc = learning_rates.Dim();
70  for (int32 i = 0; i < nc; i++)
71  std::cout << learning_rates(i) << (i < nc - 1 ? ":" : "");
72  std::cout << std::endl;
73  KALDI_LOG << "Printed learning-rate info for " << nnet_rxfilename;
74  } else {
75  std::cout << am_nnet.Info();
76  KALDI_LOG << "Printed info about " << nnet_rxfilename;
77  }
78 
79  } catch(const std::exception &e) {
80  std::cerr << e.what() << '\n';
81  return -1;
82  }
83 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int32 NumUpdatableComponents() const
Returns the number of updatable components.
Definition: nnet-nnet.cc:413
void Read(std::istream &is, bool binary)
Definition: am-nnet.cc:39
kaldi::int32 int32
std::string Info() const
Definition: am-nnet.cc:57
void GetLearningRates(VectorBase< BaseFloat > *learning_rates) const
Get all the learning rates in the neural net (the output must have dim equal to NumUpdatableComponent...
Definition: nnet-nnet.cc:476
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Read(std::istream &is, bool binary)
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_LOG
Definition: kaldi-error.h:153
const Nnet & GetNnet() const
Definition: am-nnet.h:61