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

References ParseOptions::GetArg(), Nnet::GetComponent(), Component::GetType(), KALDI_ASSERT, KALDI_LOG, Component::kRbm, ParseOptions::NumArgs(), Nnet::NumComponents(), ParseOptions::PrintUsage(), ParseOptions::Read(), Nnet::Read(), ParseOptions::Register(), Output::Stream(), and Input::Stream().

25  {
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 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int32 NumComponents() const
Returns the number of &#39;Components&#39; which form the NN.
Definition: nnet-nnet.h:66
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 Read(const std::string &rxfilename)
Read Nnet from &#39;rxfilename&#39;,.
Definition: nnet-nnet.cc:333
#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