nnet-initialize.cc
Go to the documentation of this file.
1 // nnetbin/nnet-initialize.cc
2 
3 // Copyright 2014 Brno University of Technology (author: Karel Vesely)
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 "nnet/nnet-nnet.h"
23 
24 int main(int argc, char *argv[]) {
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 }
70 
71 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Write(const std::string &wxfilename, bool binary) const
Write Nnet to &#39;wxfilename&#39;,.
Definition: nnet-nnet.cc:367
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
int main(int argc, char *argv[])
void SetVerboseLevel(int32 i)
This should be rarely used, except by programs using Kaldi as library; command-line programs set the ...
Definition: kaldi-error.h:64
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
std::ostream & Stream()
Definition: kaldi-io.cc:701
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).
void Init(const std::string &proto_file)
Initialize the Nnet from the prototype,.
Definition: nnet-nnet.cc:301
#define KALDI_LOG
Definition: kaldi-error.h:153