nnet3-discriminative-train.cc File Reference
Include dependency graph for nnet3-discriminative-train.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 26 of file nnet3-discriminative-train.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), AmNnetSimple::GetNnet(), KALDI_LOG, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), NnetDiscriminativeTrainer::PrintTotalStats(), ParseOptions::PrintUsage(), AmNnetSimple::Priors(), AmNnetSimple::Read(), ParseOptions::Read(), TransitionModel::Read(), NnetDiscriminativeOptions::Register(), ParseOptions::Register(), kaldi::nnet3::SetDropoutTestMode(), Output::Stream(), Input::Stream(), NnetDiscriminativeTrainer::Train(), SequentialTableReader< Holder >::Value(), and Nnet::Write().

26  {
27  try {
28  using namespace kaldi;
29  using namespace kaldi::nnet3;
30  typedef kaldi::int32 int32;
31  typedef kaldi::int64 int64;
32 
33  const char *usage =
34  "Train nnet3 neural network parameters with discriminative sequence objective \n"
35  "gradient descent. Minibatches are to be created by nnet3-discriminative-merge-egs in\n"
36  "the input pipeline. This training program is single-threaded (best to\n"
37  "use it with a GPU).\n"
38  "\n"
39  "Usage: nnet3-discriminative-train [options] <nnet-in> <discriminative-training-examples-in> <raw-nnet-out>\n"
40  "\n"
41  "nnet3-discriminative-train 1.mdl 'ark:nnet3-merge-egs 1.degs ark:-|' 2.raw\n";
42 
43  bool binary_write = true;
44  std::string use_gpu = "yes";
45  bool dropout_test_mode = true;
46 
48 
49  ParseOptions po(usage);
50  po.Register("binary", &binary_write, "Write output in binary mode");
51  po.Register("use-gpu", &use_gpu,
52  "yes|no|optional|wait, only has effect if compiled with CUDA");
53  po.Register("dropout-test-mode", &dropout_test_mode,
54  "If true, set test-mode to true on any DropoutComponents and "
55  "DropoutMaskComponents.");
56 
57  opts.Register(&po);
58 
59  po.Read(argc, argv);
60 
61  if (po.NumArgs() != 3) {
62  po.PrintUsage();
63  exit(1);
64  }
65 
66 #if HAVE_CUDA==1
67  CuDevice::Instantiate().SelectGpuId(use_gpu);
68 #endif
69 
70  std::string model_rxfilename = po.GetArg(1),
71  examples_rspecifier = po.GetArg(2),
72  model_wxfilename = po.GetArg(3);
73 
74  TransitionModel tmodel;
75  AmNnetSimple am_nnet;
76 
77  bool binary;
78  Input ki(model_rxfilename, &binary);
79 
80  tmodel.Read(ki.Stream(), binary);
81  am_nnet.Read(ki.Stream(), binary);
82 
83  Nnet nnet = am_nnet.GetNnet();
84 
85  if (dropout_test_mode)
86  SetDropoutTestMode(true, &nnet);
87 
88  const VectorBase<BaseFloat> &priors = am_nnet.Priors();
89 
90  NnetDiscriminativeTrainer trainer(opts, tmodel, priors, &nnet);
91 
92  SequentialNnetDiscriminativeExampleReader example_reader(examples_rspecifier);
93 
94  for (; !example_reader.Done(); example_reader.Next())
95  trainer.Train(example_reader.Value());
96 
97  bool ok = trainer.PrintTotalStats();
98 
99 #if HAVE_CUDA==1
100  CuDevice::Instantiate().PrintProfile();
101 #endif
102  Output ko(model_wxfilename, binary_write);
103  nnet.Write(ko.Stream(), binary_write);
104 
105  KALDI_LOG << "Wrote raw nnet model to " << model_wxfilename;
106  return (ok ? 0 : 1);
107  } catch(const std::exception &e) {
108  std::cerr << e.what() << '\n';
109  return -1;
110  }
111 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Write(std::ostream &ostream, bool binary) const
Definition: nnet-nnet.cc:630
kaldi::int32 int32
const Nnet & GetNnet() const
void Read(std::istream &is, bool binary)
void SetDropoutTestMode(bool test_mode, Nnet *nnet)
This function affects components of child-classes of RandomComponent.
Definition: nnet-utils.cc:573
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 &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
This class is for single-threaded discriminative training of neural nets.
const VectorBase< BaseFloat > & Priors() const
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
#define KALDI_LOG
Definition: kaldi-error.h:153