25 int main(
int argc,
char *argv[]) {
27 using namespace kaldi;
30 typedef kaldi::int64 int64;
33 "Creates a random subset of the input examples, of a specified size.\n" 34 "Uses no more memory than the size of the subset.\n" 36 "Usage: nnet3-subset-egs [options] <egs-rspecifier> [<egs-wspecifier2> ...]\n" 39 "nnet3-copy-egs [args] ark:egs.1.ark ark:- | nnet-subset-egs --n=1000 ark:- ark:subset.egs\n";
43 bool randomize_order =
true;
45 po.
Register(
"srand", &srand_seed,
"Seed for random number generator ");
46 po.
Register(
"n", &n,
"Number of examples to output");
47 po.
Register(
"randomize-order", &randomize_order,
"If true, randomize the order " 59 std::string examples_rspecifier = po.
GetArg(1),
60 examples_wspecifier = po.
GetArg(2);
62 std::vector<std::pair<std::string, NnetExample> > egs;
68 for (; !example_reader.
Done(); example_reader.
Next()) {
71 egs.resize(egs.size() + 1);
72 egs.back().first = example_reader.
Key();
73 egs.back().second = example_reader.
Value();
78 egs[index].first = example_reader.
Key();
79 egs[index].second = example_reader.
Value();
84 std::random_shuffle(egs.begin(), egs.end());
87 for (
size_t i = 0;
i < egs.size();
i++) {
88 writer.Write(egs[
i].first, egs[
i].second);
91 KALDI_LOG <<
"Selected a subset of " << egs.size() <<
" out of " << num_read
92 <<
" neural-network training examples ";
94 return (num_read != 0 ? 0 : 1);
95 }
catch(
const std::exception &e) {
96 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].
bool WithProb(BaseFloat prob, struct RandomState *state)
A templated class for writing objects to an archive or script file; see The Table concept...
void Register(const std::string &name, bool *ptr, const std::string &doc)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
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).
int main(int argc, char *argv[])
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)