nnet-get-feature-transform.cc File Reference
Include dependency graph for nnet-get-feature-transform.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 nnet-get-feature-transform.cc.

References SpMatrix< Real >::AddTp2(), FeatureTransformEstimate::Estimate(), ParseOptions::GetArg(), rnnlm::i, kaldi::kNoTrans, ParseOptions::NumArgs(), PackedMatrix< Real >::NumRows(), ParseOptions::PrintUsage(), LdaEstimate::Read(), ParseOptions::Read(), FeatureTransformEstimateOptions::Register(), ParseOptions::Register(), and kaldi::WriteKaldiObject().

25  {
26  using namespace kaldi;
27  typedef kaldi::int32 int32;
28  try {
29  const char *usage =
30  "Get feature-projection transform using stats obtained with acc-lda.\n"
31  "See comments in the code of nnet2/get-feature-transform.h for more\n"
32  "information.\n"
33  "\n"
34  "Usage: nnet-get-feature-transform [options] <matrix-out> <lda-acc-1> <lda-acc-2> ...\n";
35 
36  bool binary = true;
38  std::string write_cholesky;
39  std::string write_within_covar;
40  ParseOptions po(usage);
41  po.Register("binary", &binary, "Write outputs in binary mode.");
42  po.Register("write-cholesky", &write_cholesky, "If supplied, write to this "
43  "wxfilename the Cholesky factor of the within-class covariance. "
44  "Can be used for perturbing features. E.g. "
45  "--write-cholesky=exp/nnet5/cholesky.tpmat");
46  po.Register("write-within-covar", &write_within_covar, "If supplied, write "
47  "to this wxfilename the within-class covariance (as a symmetric "
48  "matrix). E.g. --write-within-covar=exp/nnet5/within_covar.mat");
49  opts.Register(&po);
50  po.Read(argc, argv);
51 
52  if (po.NumArgs() < 2) {
53  po.PrintUsage();
54  exit(1);
55  }
56 
58  std::string projection_wxfilename = po.GetArg(1);
59 
60  for (int32 i = 2; i <= po.NumArgs(); i++) {
61  bool binary_in, add = true;
62  Input ki(po.GetArg(i), &binary_in);
63  fte.Read(ki.Stream(), binary_in, add);
64  }
65 
67  TpMatrix<BaseFloat> cholesky;
68  fte.Estimate(opts, &mat,
69  (write_cholesky != "" || write_within_covar != "" ?
70  &cholesky : NULL));
71  WriteKaldiObject(mat, projection_wxfilename, binary);
72  if (write_cholesky != "") {
73  WriteKaldiObject(cholesky, write_cholesky, binary);
74  }
75  if (write_within_covar != "") {
76  SpMatrix<BaseFloat> within_var(cholesky.NumRows());
77  within_var.AddTp2(1.0, cholesky, kNoTrans, 0.0);
78  WriteKaldiObject(within_var, write_within_covar, binary);
79  }
80  return 0;
81  } catch(const std::exception &e) {
82  std::cerr << e.what();
83  return -1;
84  }
85 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Packed symetric matrix class.
Definition: matrix-common.h:62
void Estimate(const FeatureTransformEstimateOptions &opts, Matrix< BaseFloat > *M, TpMatrix< BaseFloat > *within_cholesky) const
Estimates the LDA transform matrix m.
kaldi::int32 int32
MatrixIndexT NumRows() const
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Read(std::istream &in_stream, bool binary, bool add)
void AddTp2(const Real alpha, const TpMatrix< Real > &T, MatrixTransposeType transM, const Real beta=0.0)
The following function does: this <– beta*this + alpha * T * T^T.
Definition: sp-matrix.cc:1156
Packed symetric matrix class.
Definition: matrix-common.h:63
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
Class for computing a feature transform used for preconditioning of the training data in neural-netwo...