nnet3-init.cc File Reference
Include dependency graph for nnet3-init.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-init.cc.

References ParseOptions::GetArg(), KALDI_ASSERT, KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), Nnet::ReadConfig(), kaldi::ReadKaldiObject(), ParseOptions::Register(), Input::Stream(), and kaldi::WriteKaldiObject().

26  {
27  try {
28  using namespace kaldi;
29  using namespace kaldi::nnet3;
30  typedef kaldi::int32 int32;
31 
32  const char *usage =
33  "Initialize nnet3 neural network from a config file; outputs 'raw' nnet\n"
34  "without associated information such as transition model and priors.\n"
35  "Search for examples in scripts in /egs/wsj/s5/steps/nnet3/\n"
36  "Can also be used to add layers to existing model (provide existing model\n"
37  "as 1st arg)\n"
38  "\n"
39  "Usage: nnet3-init [options] [<existing-model-in>] <config-in> <raw-nnet-out>\n"
40  "e.g.:\n"
41  " nnet3-init nnet.config 0.raw\n"
42  "or: nnet3-init 1.raw nnet.config 2.raw\n"
43  "See also: nnet3-copy, nnet3-info\n";
44 
45  bool binary_write = true;
46  int32 srand_seed = 0;
47 
48  ParseOptions po(usage);
49  po.Register("binary", &binary_write, "Write output in binary mode");
50  po.Register("srand", &srand_seed, "Seed for random number generator");
51 
52  po.Read(argc, argv);
53  srand(srand_seed);
54 
55  if (po.NumArgs() < 2 || po.NumArgs() > 3) {
56  po.PrintUsage();
57  exit(1);
58  }
59 
60  std::string raw_nnet_rxfilename = (po.NumArgs() == 3 ?
61  po.GetArg(1) : std::string("")),
62  config_rxfilename = po.GetArg(po.NumArgs() == 3 ? 2 : 1),
63  raw_nnet_wxfilename = po.GetArg(po.NumArgs() == 3 ? 3 : 2);
64 
65  Nnet nnet;
66  if (po.NumArgs() == 3) {
67  ReadKaldiObject(raw_nnet_rxfilename, &nnet);
68  KALDI_LOG << "Read raw neural net from "
69  << raw_nnet_rxfilename;
70  }
71 
72  {
73  bool binary;
74  Input ki(config_rxfilename, &binary);
75  KALDI_ASSERT(!binary && "Expect config file to contain text.");
76  nnet.ReadConfig(ki.Stream());
77  }
78 
79  WriteKaldiObject(nnet, raw_nnet_wxfilename, binary_write);
80  KALDI_LOG << "Initialized raw neural net and wrote it to "
81  << raw_nnet_wxfilename;
82  return 0;
83  } catch(const std::exception &e) {
84  std::cerr << e.what() << '\n';
85  return -1;
86  }
87 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void ReadConfig(std::istream &config_file)
Definition: nnet-nnet.cc:189
kaldi::int32 int32
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153