transf-to-nnet.cc File Reference
Include dependency graph for transf-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 transf-to-nnet.cc.

References Nnet::AppendComponent(), ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), Matrix< Real >::Read(), ParseOptions::Register(), LinearTransform::SetLinearity(), Output::Stream(), Input::Stream(), and Nnet::Write().

25  {
26  try {
27  using namespace kaldi;
28  using namespace kaldi::nnet1;
29  typedef kaldi::int32 int32;
30 
31  const char *usage =
32  "Convert transformation matrix to <affine-transform>\n"
33  "Usage: transf-to-nnet [options] <transf-in> <nnet-out>\n"
34  "e.g.:\n"
35  " transf-to-nnet --binary=false transf.mat nnet.mdl\n";
36 
37  bool binary_write = false;
38 
39  ParseOptions po(usage);
40  po.Register("binary", &binary_write, "Write output in binary mode");
41 
42  po.Read(argc, argv);
43 
44  if (po.NumArgs() != 2) {
45  po.PrintUsage();
46  exit(1);
47  }
48 
49  std::string transform_rxfilename = po.GetArg(1),
50  model_out_filename = po.GetArg(2);
51 
52  // read the matrix,
53  Matrix<BaseFloat> transform;
54  {
55  bool binary_read;
56  Input ki(transform_rxfilename, &binary_read);
57  transform.Read(ki.Stream(), binary_read);
58  }
59 
60  // wrapping as Nnet with <LinearTransform>,
61  Nnet nnet;
62  LinearTransform lin_tran(transform.NumCols(), transform.NumRows());
63  lin_tran.SetLinearity(transform);
64  nnet.AppendComponent(lin_tran);
65 
66  // write the nnet,
67  {
68  Output ko(model_out_filename, binary_write);
69  nnet.Write(ko.Stream(), binary_write);
70  KALDI_LOG << "Written transform in 'nnet1' model: " << model_out_filename;
71  }
72  return 0;
73  } catch(const std::exception &e) {
74  std::cerr << e.what();
75  return -1;
76  }
77 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
void Write(const std::string &wxfilename, bool binary) const
Write Nnet to &#39;wxfilename&#39;,.
Definition: nnet-nnet.cc:367
kaldi::int32 int32
void Read(std::istream &in, bool binary, bool add=false)
read from stream.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void SetLinearity(const MatrixBase< BaseFloat > &l)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
#define KALDI_LOG
Definition: kaldi-error.h:153
void AppendComponent(const Component &comp)
Append Component to &#39;this&#39; instance of Nnet (deep copy),.
Definition: nnet-nnet.cc:182