29 using namespace kaldi;
34 "This program is for adding new layers to a neural-network acoustic model.\n" 35 "It removes the last --remove-layers layers, and adds the layers from the\n" 36 "supplied raw-nnet. The typical use is to remove the last two layers\n" 37 "(the softmax, and the affine component before it), and add in replacements\n" 38 "for them newly initialized by nnet-init. This program is a more flexible\n" 39 "way of adding layers than nnet-insert, but the inserted network needs to\n" 40 "contain replacements for the removed layers.\n" 42 "Usage: nnet-replace-last-layers [options] <nnet-in> <raw-nnet-to-insert-in> <nnet-out>\n" 44 " nnet-replace-last-layers 1.nnet \"nnet-init hidden_layer.config -|\" 2.nnet\n";
46 bool binary_write =
true;
47 int32 remove_layers = 2;
51 po.Register(
"binary", &binary_write,
"Write output in binary mode");
52 po.Register(
"remove-layers", &remove_layers,
"Number of final layers " 53 "to remove before adding input raw network.");
57 if (po.NumArgs() != 3) {
62 std::string nnet_rxfilename = po.GetArg(1),
63 raw_nnet_rxfilename = po.GetArg(2),
64 nnet_wxfilename = po.GetArg(3);
70 Input ki(nnet_rxfilename, &binary);
71 trans_model.
Read(ki.Stream(), binary);
72 am_nnet.
Read(ki.Stream(), binary);
83 KALDI_LOG <<
"Removed " << remove_layers <<
" components and added " 87 Output ko(nnet_wxfilename, binary_write);
88 trans_model.
Write(ko.Stream(), binary_write);
89 am_nnet.
Write(ko.Stream(), binary_write);
91 KALDI_LOG <<
"Write neural-net acoustic model 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 ReadKaldiObject(const std::string &filename, Matrix< float > *m)
int32 NumComponents() const
Returns number of components– think of this as similar to # of layers, but e.g.
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 ReplaceLastComponents(const Nnet &src_nnet, int32 num_to_remove, Nnet *dest_nnet)
Removes the last "num_to_remove" components and adds the components from "src_nnet".
void Write(std::ostream &os, bool binary) const
const Nnet & GetNnet() const