nnet-concat.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "nnet/nnet-nnet.h"
Include dependency graph for nnet-concat.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 24 of file nnet-concat.cc.

References Nnet::AppendNnet(), ParseOptions::GetArg(), rnnlm::i, KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), Nnet::Read(), ParseOptions::Register(), Output::Stream(), Input::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  "Concatenate Neural Networks (and possibly change binary/text format)\n"
32  "Usage: nnet-concat [options] <nnet-in1> <...> <nnet-inN> <nnet-out>\n"
33  "e.g.:\n"
34  " nnet-concat --binary=false nnet.1 nnet.2 nnet.1.2\n";
35 
36  ParseOptions po(usage);
37 
38  bool binary_write = true;
39  po.Register("binary", &binary_write, "Write output in binary mode");
40 
41  po.Read(argc, argv);
42 
43  if (po.NumArgs() < 3) {
44  po.PrintUsage();
45  exit(1);
46  }
47 
48  std::string model_in_filename = po.GetArg(1);
49  std::string model_in_filename_next;
50  std::string model_out_filename = po.GetArg(po.NumArgs());
51 
52  // read the first nnet,
53  KALDI_LOG << "Reading " << model_in_filename;
54  Nnet nnet;
55  {
56  bool binary_read;
57  Input ki(model_in_filename, &binary_read);
58  nnet.Read(ki.Stream(), binary_read);
59  }
60 
61  // read all the other nnets,
62  for (int32 i = 2; i < po.NumArgs(); i++) {
63  // read the nnet,
64  model_in_filename_next = po.GetArg(i);
65  KALDI_LOG << "Concatenating " << model_in_filename_next;
66  Nnet nnet_next;
67  {
68  bool binary_read;
69  Input ki(model_in_filename_next, &binary_read);
70  nnet_next.Read(ki.Stream(), binary_read);
71  }
72  // append nnet_next to the network nnet,
73  nnet.AppendNnet(nnet_next);
74  }
75 
76  // finally write the nnet to disk,
77  {
78  Output ko(model_out_filename, binary_write);
79  nnet.Write(ko.Stream(), binary_write);
80  }
81 
82  KALDI_LOG << "Written model to " << model_out_filename;
83  return 0;
84  } catch(const std::exception &e) {
85  std::cerr << e.what();
86  return -1;
87  }
88 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Write(const std::string &wxfilename, bool binary) const
Write Nnet to &#39;wxfilename&#39;,.
Definition: nnet-nnet.cc:367
kaldi::int32 int32
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void AppendNnet(const Nnet &nnet_to_append)
Append other Nnet to the &#39;this&#39; Nnet (copy all its components),.
Definition: nnet-nnet.cc:192
void Read(const std::string &rxfilename)
Read Nnet from &#39;rxfilename&#39;,.
Definition: nnet-nnet.cc:333
#define KALDI_LOG
Definition: kaldi-error.h:153