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

References ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), Output::Stream(), AmNnetSimple::Write(), and TransitionModel::Write().

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 am-nnet (i.e. neural network-based acoustic model, with\n"
34  "associated transition model) from an existing transition model and nnet..\n"
35  "Search for examples in scripts in /egs/wsj/s5/steps/nnet3/\n"
36  "Set priors using nnet3-am-train-transitions or nnet3-am-adjust-priors\n"
37  "\n"
38  "Usage: nnet3-am-init [options] <tree-in> <topology-in> <input-raw-nnet> <output-am-nnet>\n"
39  " or: nnet3-am-init [options] <trans-model-in> <input-raw-nnet> <output-am-nnet>\n"
40  "e.g.:\n"
41  " nnet3-am-init tree topo 0.raw 0.mdl\n"
42  "See also: nnet3-init, nnet3-am-copy, nnet3-am-info, nnet3-am-train-transitions,\n"
43  " nnet3-am-adjust-priors\n";
44 
45  bool binary_write = true;
46 
47  ParseOptions po(usage);
48  po.Register("binary", &binary_write, "Write output in binary mode");
49 
50  po.Read(argc, argv);
51 
52  if (po.NumArgs() < 3 || po.NumArgs() > 4) {
53  po.PrintUsage();
54  exit(1);
55  }
56 
57  std::string raw_nnet_rxfilename,
58  am_nnet_wxfilename;
59  TransitionModel *trans_model = NULL;
60 
61  if (po.NumArgs() == 4) {
62  std::string tree_rxfilename = po.GetArg(1),
63  topo_rxfilename = po.GetArg(2);
64  raw_nnet_rxfilename = po.GetArg(3);
65  am_nnet_wxfilename = po.GetArg(4);
66 
67  ContextDependency ctx_dep;
68  ReadKaldiObject(tree_rxfilename, &ctx_dep);
69 
70  HmmTopology topo;
71  ReadKaldiObject(topo_rxfilename, &topo);
72 
73  // Construct the transition model from the tree and the topology file.
74  trans_model = new TransitionModel(ctx_dep, topo);
75  } else {
76  std::string trans_model_rxfilename = po.GetArg(1);
77  raw_nnet_rxfilename = po.GetArg(2);
78  am_nnet_wxfilename = po.GetArg(3);
79 
80  trans_model = new TransitionModel();
81  ReadKaldiObject(trans_model_rxfilename, trans_model);
82  }
83 
84  Nnet nnet;
85  ReadKaldiObject(raw_nnet_rxfilename, &nnet);
86 
87  // priors won't be set yet.
88  AmNnetSimple am_nnet(nnet);
89 
90  {
91  Output ko(am_nnet_wxfilename, binary_write);
92  trans_model->Write(ko.Stream(), binary_write);
93  am_nnet.Write(ko.Stream(), binary_write);
94  }
95  delete trans_model;
96  KALDI_LOG << "Initialized am-nnet (neural net acoustic model) and wrote to "
97  << am_nnet_wxfilename;
98  return 0;
99  } catch(const std::exception &e) {
100  std::cerr << e.what() << '\n';
101  return -1;
102  }
103 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
A class for storing topology information for phones.
Definition: hmm-topology.h:93
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
void Write(std::ostream &os, bool binary) const
#define KALDI_LOG
Definition: kaldi-error.h:153