nnet-am-info.cc
Go to the documentation of this file.
1 // nnet2bin/nnet-am-info.cc
2 
3 // Copyright 2012 Johns Hopkins University (author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #include "base/kaldi-common.h"
21 #include "util/common-utils.h"
22 #include "hmm/transition-model.h"
23 #include "nnet2/am-nnet.h"
24 
25 int main(int argc, char *argv[]) {
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 }
84 
85 
86 
87 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int main(int argc, char *argv[])
Definition: nnet-am-info.cc:25
int32 NumUpdatableComponents() const
Returns the number of updatable components.
Definition: nnet-nnet.cc:413
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
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 Register(const std::string &name, bool *ptr, const std::string &doc)
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
std::istream & Stream()
Definition: kaldi-io.cc:826
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)
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
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