All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
nnet-initialize.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "nnet/nnet-nnet.h"
Include dependency graph for nnet-initialize.cc:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 24 of file nnet-initialize.cc.

References ParseOptions::GetArg(), Nnet::Init(), KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), kaldi::SetVerboseLevel(), Output::Stream(), and Nnet::Write().

24  {
25  try {
26  using namespace kaldi;
27  using namespace kaldi::nnet1;
28  typedef kaldi::int32 int32;
29 
30  const char *usage =
31  "Initialize Neural Network parameters according to a prototype (nnet1).\n"
32  "Usage: nnet-initialize [options] <nnet-prototype-in> <nnet-out>\n"
33  "e.g.: nnet-initialize --binary=false nnet.proto nnet.init\n";
34 
35  SetVerboseLevel(1); // be verbose by default,
36 
37  ParseOptions po(usage);
38  bool binary_write = true;
39  po.Register("binary", &binary_write, "Write output in binary mode");
40  int32 seed = 777;
41  po.Register("seed", &seed, "Seed for random number generator");
42 
43  po.Read(argc, argv);
44 
45  if (po.NumArgs() != 2) {
46  po.PrintUsage();
47  exit(1);
48  }
49 
50  std::string nnet_config_in_filename = po.GetArg(1),
51  nnet_out_filename = po.GetArg(2);
52 
53  std::srand(seed);
54 
55  // initialize the network
56  Nnet nnet;
57  nnet.Init(nnet_config_in_filename);
58 
59  // store the network
60  Output ko(nnet_out_filename, binary_write);
61  nnet.Write(ko.Stream(), binary_write);
62 
63  KALDI_LOG << "Written initialized model to " << nnet_out_filename;
64  return 0;
65  } catch(const std::exception &e) {
66  std::cerr << e.what();
67  return -1;
68  }
69 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
void SetVerboseLevel(int32 i)
This should be rarely used; command-line programs set the verbose level automatically from ParseOptio...
Definition: kaldi-error.h:73
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Init(const std::string &proto_file)
Initialize the Nnet from the prototype,.
Definition: nnet-nnet.cc:301
void Write(const std::string &wxfilename, bool binary) const
Write Nnet to 'wxfilename',.
Definition: nnet-nnet.cc:367
#define KALDI_LOG
Definition: kaldi-error.h:133