nnet1-to-raw-nnet.cc File Reference
Include dependency graph for nnet1-to-raw-nnet.cc:

Go to the source code of this file.

Namespaces

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

Functions

nnet2::ComponentConvertAffineTransformComponent (const nnet1::Component &nnet1_component, const bool use_preconditioned_affine_component)
 
nnet2::ComponentConvertSoftmaxComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertSigmoidComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertSpliceComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertAddShiftComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertRescaleComponent (const nnet1::Component &nnet1_component)
 
nnet2::ComponentConvertComponent (const nnet1::Component &nnet1_component, const bool use_preconditioned_affine_component)
 
nnet2::NnetConvertNnet1ToNnet2 (const nnet1::Nnet &nnet1, const bool use_preconditioned_affine_component)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 176 of file nnet1-to-raw-nnet.cc.

References kaldi::ConvertNnet1ToNnet2(), ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), kaldi::PrintableWxfilename(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), and kaldi::WriteKaldiObject().

176  {
177  try {
178  using namespace kaldi;
179  typedef kaldi::int32 int32;
180 
181  const char *usage =
182  "Convert nnet1 neural net to nnet2 'raw' neural net\n"
183  "\n"
184  "Usage: nnet1-to-raw-nnet [options] <nnet1-in> <nnet2-out>\n"
185  "e.g.:\n"
186  " nnet1-to-raw-nnet srcdir/final.nnet - | nnet-am-init dest/tree dest/topo - dest/0.mdl\n";
187 
188  bool binary_write = true, use_preconditioned_affine_component = false;
189  int32 srand_seed = 0;
190 
191  ParseOptions po(usage);
192  po.Register("binary", &binary_write, "Write output in binary mode");
193 
194  po.Register("use_preconditioned_affine_component",
195  &use_preconditioned_affine_component,
196  "Using AffineComponentPreconditionOnline instead AffineComponent");
197 
198  po.Read(argc, argv);
199  srand(srand_seed);
200 
201  if (po.NumArgs() != 2) {
202  po.PrintUsage();
203  exit(1);
204  }
205 
206  std::string nnet1_rxfilename = po.GetArg(1),
207  raw_nnet2_wxfilename = po.GetArg(2);
208 
209  nnet1::Nnet nnet1;
210  ReadKaldiObject(nnet1_rxfilename, &nnet1);
211  nnet2::Nnet *nnet2 = ConvertNnet1ToNnet2(nnet1,
212  use_preconditioned_affine_component);
213  WriteKaldiObject(*nnet2, raw_nnet2_wxfilename, binary_write);
214  KALDI_LOG << "Converted nnet1 neural net to raw nnet2 and wrote it to "
215  << PrintableWxfilename(raw_nnet2_wxfilename);
216  delete nnet2;
217  return 0;
218  } catch(const std::exception &e) {
219  std::cerr << e.what() << '\n';
220  return -1;
221  }
222 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
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
nnet2::Nnet * ConvertNnet1ToNnet2(const nnet1::Nnet &nnet1, const bool use_preconditioned_affine_component)
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:73
#define KALDI_LOG
Definition: kaldi-error.h:153