rbm-convert-to-nnet.cc
Go to the documentation of this file.
1 // nnetbin/rbm-convert-to-nnet.cc
2 
3 // Copyright 2009-2011 Microsoft Corporation
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 #include "nnet/nnet-rbm.h"
24 
25 int main(int argc, char *argv[]) {
26  try {
27  using namespace kaldi;
28  using namespace kaldi::nnet1;
29  typedef kaldi::int32 int32;
30 
31  const char *usage =
32  "Convert RBM to <affinetransform> and <sigmoid>\n"
33  "Usage: rbm-convert-to-nnet [options] <rbm-in> <nnet-out>\n"
34  "e.g.:\n"
35  " rbm-convert-to-nnet --binary=false rbm.mdl nnet.mdl\n";
36 
37 
38  bool binary_write = true;
39 
40  ParseOptions po(usage);
41  po.Register("binary", &binary_write, "Write output in binary mode");
42 
43  po.Read(argc, argv);
44 
45  if (po.NumArgs() != 2) {
46  po.PrintUsage();
47  exit(1);
48  }
49 
50  std::string model_in_filename = po.GetArg(1),
51  model_out_filename = po.GetArg(2);
52 
53  Nnet nnet;
54  {
55  bool binary_read;
56  Input ki(model_in_filename, &binary_read);
57  nnet.Read(ki.Stream(), binary_read);
58  }
59 
60  KALDI_ASSERT(nnet.NumComponents() == 1);
62  RbmBase& rbm = dynamic_cast<RbmBase&>(nnet.GetComponent(0));
63 
64  {
65  Output ko(model_out_filename, binary_write);
66  rbm.WriteAsNnet(ko.Stream(), binary_write);
67  }
68 
69  KALDI_LOG << "Written model to " << model_out_filename;
70  return 0;
71  } catch(const std::exception &e) {
72  std::cerr << e.what();
73  return -1;
74  }
75 }
76 
77 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int main(int argc, char *argv[])
int32 NumComponents() const
Returns the number of &#39;Components&#39; which form the NN.
Definition: nnet-nnet.h:66
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
std::istream & Stream()
Definition: kaldi-io.cc:826
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.
void Read(const std::string &rxfilename)
Read Nnet from &#39;rxfilename&#39;,.
Definition: nnet-nnet.cc:333
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).
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
const Component & GetComponent(int32 c) const
Component accessor,.
Definition: nnet-nnet.cc:153
virtual ComponentType GetType() const =0
Get Type Identification of the component,.
#define KALDI_LOG
Definition: kaldi-error.h:153