raw-nnet-concat.cc
Go to the documentation of this file.
1 // nnet2bin/raw-nnet-concat.cc
2 
3 // Copyright 2013 Johns Hopkins University (author: Daniel Povey)
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 "nnet2/am-nnet.h"
23 #include "hmm/transition-model.h"
24 #include "tree/context-dep.h"
25 
26 int main(int argc, char *argv[]) {
27  try {
28  using namespace kaldi;
29  using namespace kaldi::nnet2;
30  typedef kaldi::int32 int32;
31 
32  const char *usage =
33  "Concatenate two 'raw' neural nets, e.g. as output by nnet-init or\n"
34  "nnet-to-raw-nnet\n"
35  "\n"
36  "Usage: raw-nnet-concat [options] <raw-nnet-in1> <raw-nnet-in2> <raw-nnet-out>\n"
37  "e.g.:\n"
38  " raw-nnet-concat nnet1 nnet2 nnet_concat\n";
39 
40  bool binary_write = true;
41  int32 srand_seed = 0;
42 
43  ParseOptions po(usage);
44  po.Register("binary", &binary_write, "Write output in binary mode");
45 
46  po.Read(argc, argv);
47  srand(srand_seed);
48 
49  if (po.NumArgs() != 3) {
50  po.PrintUsage();
51  exit(1);
52  }
53 
54  std::string raw_nnet1_rxfilename = po.GetArg(1),
55  raw_nnet2_rxfilename = po.GetArg(2),
56  raw_nnet_wxfilename = po.GetArg(3);
57 
58  Nnet nnet1;
59  ReadKaldiObject(raw_nnet1_rxfilename, &nnet1);
60  Nnet nnet2;
61  ReadKaldiObject(raw_nnet2_rxfilename, &nnet2);
62 
63  Nnet nnet_concat(nnet1, nnet2); // Constructor concatenates them.
64 
65  WriteKaldiObject(nnet_concat, raw_nnet_wxfilename, binary_write);
66 
67  KALDI_LOG << "Concatenated neural nets from "
68  << raw_nnet1_rxfilename << " and " << raw_nnet2_rxfilename
69  << " and wrote to " << raw_nnet_wxfilename;
70  return 0;
71  } catch(const std::exception &e) {
72  std::cerr << e.what() << '\n';
73  return -1;
74  }
75 }
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].
kaldi::int32 int32
int main(int argc, char *argv[])
void Register(const std::string &name, bool *ptr, const std::string &doc)
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
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 WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153