25 int main(
int argc,
char *argv[]) {
27 using namespace kaldi;
30 typedef kaldi::int64 int64;
33 "Copy examples (typically single frames) for neural network training,\n" 34 "from the input to output, but randomly shuffle the order. This program will keep\n" 35 "all of the examples in memory at once, so don't give it too many.\n" 37 "Usage: nnet-shuffle-egs-discriminative [options] <egs-rspecifier> <egs-wspecifier>\n" 39 "nnet-shuffle-egs-discriminative --srand=1 ark:train.degs ark:shuffled.degs\n";
42 int32 buffer_size = 0;
44 po.
Register(
"srand", &srand_seed,
"Seed for random number generator ");
45 po.
Register(
"buffer-size", &buffer_size,
"If >0, size of a buffer we use " 46 "to do limited-memory partial randomization. Otherwise, do " 47 "full randomization.");
58 std::string examples_rspecifier = po.
GetArg(1),
59 examples_wspecifier = po.
GetArg(2);
63 std::vector<DiscriminativeNnetExample*> egs;
68 if (buffer_size == 0) {
72 for (; !example_reader.
Done(); example_reader.
Next())
74 example_reader.
Value()));
76 std::random_shuffle(egs.begin(), egs.end());
79 egs.resize(buffer_size, NULL);
80 for (; !example_reader.
Done(); example_reader.
Next()) {
81 int32 index =
RandInt(0, buffer_size - 1);
82 if (egs[index] == NULL) {
85 std::ostringstream ostr;
87 example_writer.
Write(ostr.str(), *(egs[index]));
88 *(egs[index]) = example_reader.
Value();
93 for (
size_t i = 0;
i < egs.size();
i++) {
94 std::ostringstream ostr;
97 example_writer.
Write(ostr.str(), *(egs[
i]));
103 KALDI_LOG <<
"Shuffled order of " << num_done
104 <<
" neural-network training examples " 105 << (buffer_size ?
"using a buffer (partial randomization)" :
"");
107 return (num_done == 0 ? 1 : 0);
108 }
catch(
const std::exception &e) {
109 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].
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
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 main(int argc, char *argv[])
int NumArgs() const
Number of positional parameters (c.f. argc-1).
This struct is used to store the information we need for discriminative training (MMI or MPE)...
#define KALDI_ASSERT(cond)
Note on how to parse this filename: it contains functions relatied to neural-net training examples...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)