nnet3-compute-from-egs.cc File Reference
Include dependency graph for nnet3-compute-from-egs.cc:

Go to the source code of this file.

Classes

class  NnetComputerFromEg
 

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 
 kaldi::nnet3
 

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 66 of file nnet3-compute-from-egs.cc.

References MatrixBase< Real >::ApplyExp(), NnetComputerFromEg::Compute(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ASSERT, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

66  {
67  try {
68  using namespace kaldi;
69  using namespace kaldi::nnet3;
70  typedef kaldi::int32 int32;
71  typedef kaldi::int64 int64;
72 
73  const char *usage =
74  "Read input nnet training examples, and compute the output for each one.\n"
75  "If --apply-exp=true, apply the Exp() function to the output before writing\n"
76  "it out.\n"
77  "\n"
78  "Usage: nnet3-compute-from-egs [options] <raw-nnet-in> <training-examples-in> <matrices-out>\n"
79  "e.g.:\n"
80  "nnet3-compute-from-egs --apply-exp=true 0.raw ark:1.egs ark:- | matrix-sum-rows ark:- ... \n"
81  "See also: nnet3-compute\n";
82 
83  bool binary_write = true,
84  apply_exp = false;
85  std::string use_gpu = "yes";
86  std::string output_name = "output";
87 
88  ParseOptions po(usage);
89  po.Register("binary", &binary_write, "Write output in binary mode");
90  po.Register("apply-exp", &apply_exp, "If true, apply exp function to "
91  "output");
92  po.Register("output-name", &output_name, "Do computation for "
93  "specified output-node");
94  po.Register("use-gpu", &use_gpu,
95  "yes|no|optional|wait, only has effect if compiled with CUDA");
96 
97  po.Read(argc, argv);
98 
99  if (po.NumArgs() != 3) {
100  po.PrintUsage();
101  exit(1);
102  }
103 
104 #if HAVE_CUDA==1
105  CuDevice::Instantiate().SelectGpuId(use_gpu);
106 #endif
107 
108  std::string nnet_rxfilename = po.GetArg(1),
109  examples_rspecifier = po.GetArg(2),
110  matrix_wspecifier = po.GetArg(3);
111 
112  Nnet nnet;
113  ReadKaldiObject(nnet_rxfilename, &nnet);
114 
115  NnetComputerFromEg computer(nnet);
116 
117  int64 num_egs = 0;
118 
119  SequentialNnetExampleReader example_reader(examples_rspecifier);
120  BaseFloatMatrixWriter matrix_writer(matrix_wspecifier);
121 
122  for (; !example_reader.Done(); example_reader.Next(), num_egs++) {
123  Matrix<BaseFloat> output;
124  computer.Compute(example_reader.Value(), output_name, &output);
125  KALDI_ASSERT(output.NumRows() != 0);
126  if (apply_exp)
127  output.ApplyExp();
128  matrix_writer.Write(example_reader.Key(), output);
129  }
130 #if HAVE_CUDA==1
131  CuDevice::Instantiate().PrintProfile();
132 #endif
133  KALDI_LOG << "Processed " << num_egs << " examples.";
134  return 0;
135  } catch(const std::exception &e) {
136  std::cerr << e.what() << '\n';
137  return -1;
138  }
139 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
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
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
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