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

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

26  {
27  try {
28  using namespace kaldi;
29  using namespace kaldi::nnet2;
30  typedef kaldi::int32 int32;
31 
32  const char *usage =
33  "Initialize the nnet2 neural network from a config file with a line for each\n"
34  "component. Note, this only outputs the neural net itself, not the associated\n"
35  "information such as the transition-model; you'll probably want to pipe\n"
36  "the output into something like nnet-am-init.\n"
37  "\n"
38  "Usage: nnet-init [options] <config-in> <raw-nnet-out>\n"
39  "e.g.:\n"
40  " nnet-init nnet.config 1.raw\n";
41 
42  bool binary_write = true;
43  int32 srand_seed = 0;
44 
45  ParseOptions po(usage);
46  po.Register("binary", &binary_write, "Write output in binary mode");
47  po.Register("srand", &srand_seed, "Seed for random number generator");
48 
49  po.Read(argc, argv);
50  srand(srand_seed);
51 
52  if (po.NumArgs() != 2) {
53  po.PrintUsage();
54  exit(1);
55  }
56 
57  std::string config_rxfilename = po.GetArg(1),
58  raw_nnet_wxfilename = po.GetArg(2);
59 
60  Nnet nnet;
61  {
62  bool binary;
63  Input ki(config_rxfilename, &binary);
64  KALDI_ASSERT(!binary && "Expect config file to contain text.");
65  nnet.Init(ki.Stream());
66  }
67 
68  WriteKaldiObject(nnet, raw_nnet_wxfilename, binary_write);
69  KALDI_LOG << "Initialized raw neural net and wrote it to "
70  << raw_nnet_wxfilename;
71  return 0;
72  } catch(const std::exception &e) {
73  std::cerr << e.what() << '\n';
74  return -1;
75  }
76 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
kaldi::int32 int32
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 Init(std::istream &is)
Initialize from config file.
Definition: nnet-nnet.cc:281
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153