28 using namespace kaldi;
33 "Copy a (cpu-based) neural net and its associated transition model,\n" 34 "and switch it to online preconditioning, i.e. change any components\n" 35 "derived from AffineComponent to components of type\n" 36 "AffineComponentPreconditionedOnline.\n" 38 "Usage: nnet-am-switch-preconditioning [options] <nnet-in> <nnet-out>\n" 40 " nnet-am-switch-preconditioning --binary=false 1.mdl text.mdl\n";
42 int32 rank_in = 20, rank_out = 80, update_period = 4;
45 bool binary_write =
true;
48 po.Register(
"binary", &binary_write,
"Write output in binary mode");
49 po.Register(
"rank-in", &rank_in,
50 "Rank used in online-preconditioning on input side of each layer");
51 po.Register(
"rank-out", &rank_out,
52 "Rank used in online-preconditioning on output side of each layer");
53 po.Register(
"update-period", &update_period,
54 "Affects how frequently we update the Fisher-matrix estimate (every " 55 "this-many minibatches).");
56 po.Register(
"num-samples-history", &num_samples_history,
57 "Number of samples of history to use in online preconditioning " 58 "(affects speed vs accuracy of update of Fisher matrix)");
59 po.Register(
"alpha", &alpha,
60 "Parameter that affects amount of smoothing with unit matrix " 61 "in online preconditioning (larger -> more smoothing)");
65 if (po.NumArgs() != 2) {
70 std::string nnet_rxfilename = po.GetArg(1),
71 nnet_wxfilename = po.GetArg(2);
77 Input ki(nnet_rxfilename, &binary);
78 trans_model.
Read(ki.Stream(), binary);
79 am_nnet.
Read(ki.Stream(), binary);
83 num_samples_history, alpha);
86 Output ko(nnet_wxfilename, binary_write);
87 trans_model.
Write(ko.Stream(), binary_write);
88 am_nnet.
Write(ko.Stream(), binary_write);
90 KALDI_LOG <<
"Copied neural net from " << nnet_rxfilename
91 <<
" to " << nnet_wxfilename;
93 }
catch(
const std::exception &e) {
94 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Read(std::istream &is, bool binary)
void SwitchToOnlinePreconditioning(int32 rank_in, int32 rank_out, int32 update_period, BaseFloat num_samples_history, BaseFloat alpha)
Replaces any components of type AffineComponent or derived classes, with components of type AffineCom...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
void Write(std::ostream &os, bool binary) const
void Write(std::ostream &os, bool binary) const
const Nnet & GetNnet() const