27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
32 typedef kaldi::int64 int64;
35 "Using a validation set, compute an optimal combination of a number of\n" 36 "neural nets (the combination weights are separate for each layer and\n" 37 "do not have to sum to one). The optimization is BFGS, which is initialized\n" 38 "from the best of the individual input neural nets (or as specified by\n" 41 "Usage: nnet-combine-fast [options] <model-in1> <model-in2> ... <model-inN> <valid-examples-in> <model-out>\n" 44 " nnet-combine-fast 1.1.nnet 1.2.nnet 1.3.nnet ark:valid.egs 2.nnet\n" 45 "Caution: the first input neural net must not be a gradient.\n";
47 bool binary_write =
true;
49 std::string use_gpu =
"yes";
52 po.
Register(
"binary", &binary_write,
"Write output in binary mode");
54 "yes|no|optional|wait, only has effect if compiled with CUDA");
66 nnet1_rxfilename = po.
GetArg(1),
72 CuDevice::Instantiate().SelectGpuId(use_gpu);
80 Input ki(nnet1_rxfilename, &binary_read);
85 int32 num_nnets = po.
NumArgs() - 2;
86 std::vector<Nnet> nnets(num_nnets);
90 for (int32
n = 1;
n < num_nnets;
n++) {
95 trans_model.
Read(ki.Stream(), binary_read);
96 am_nnet.
Read(ki.Stream(), binary_read);
100 std::vector<NnetExample> validation_set;
105 valid_examples_rspecifier);
106 for (; !example_reader.
Done(); example_reader.
Next())
107 validation_set.push_back(example_reader.
Value());
108 KALDI_LOG <<
"Read " << validation_set.size() <<
" examples from the " 109 <<
"validation set.";
119 Output ko(nnet_wxfilename, binary_write);
124 KALDI_LOG <<
"Finished combining neural nets, wrote model to " 126 return (validation_set.size() == 0 ? 1 : 0);
127 }
catch(
const std::exception &e) {
128 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Read(std::istream &is, bool binary)
void Register(const std::string &name, bool *ptr, const std::string &doc)
int main(int argc, char *argv[])
void CombineNnetsFast(const NnetCombineFastConfig &combine_config, const std::vector< NnetExample > &validation_set, const std::vector< Nnet > &nnets_in, Nnet *nnet_out)
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
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void Write(std::ostream &os, bool binary) const
#define KALDI_ASSERT(cond)
Configuration class that controls neural net combination, where we combine a number of neural nets...
const Nnet & GetNnet() const
void Register(OptionsItf *opts)