28 using namespace kaldi;
31 typedef kaldi::int64 int64;
34 "Copy examples (typically single frames) for neural network training,\n" 35 "from the input to output, but randomly shuffle the order. This program will keep\n" 36 "all of the examples in memory at once, unless you use the --buffer-size option\n" 38 "Usage: nnet-shuffle-egs [options] <egs-rspecifier> <egs-wspecifier>\n" 40 "nnet-shuffle-egs --srand=1 ark:train.egs ark:shuffled.egs\n";
43 int32 buffer_size = 0;
45 po.Register(
"srand", &srand_seed,
"Seed for random number generator ");
46 po.Register(
"buffer-size", &buffer_size,
"If >0, size of a buffer we use " 47 "to do limited-memory partial randomization. Otherwise, do " 48 "full randomization.");
54 if (po.NumArgs() != 2) {
59 std::string examples_rspecifier = po.GetArg(1),
60 examples_wspecifier = po.GetArg(2);
64 std::vector<std::pair<std::string, NnetExample*> > egs;
68 if (buffer_size == 0) {
72 for (; !example_reader.Done(); example_reader.Next())
73 egs.push_back(std::make_pair(example_reader.Key(),
76 std::random_shuffle(egs.begin(), egs.end());
79 egs.resize(buffer_size,
80 std::pair<std::string, NnetExample*>(
"", static_cast<NnetExample *>(NULL)));
81 for (; !example_reader.Done(); example_reader.Next()) {
82 int32 index =
RandInt(0, buffer_size - 1);
83 if (egs[index].second == NULL) {
84 egs[index] = std::make_pair(example_reader.Key(),
87 example_writer.Write(egs[index].first, *(egs[index].second));
88 egs[index].first = example_reader.Key();
89 *(egs[index].second) = example_reader.Value();
94 for (
size_t i = 0;
i < egs.size();
i++) {
95 if (egs[
i].second != NULL) {
96 example_writer.Write(egs[
i].first, *(egs[
i].second));
102 KALDI_LOG <<
"Shuffled order of " << num_done
103 <<
" neural-network training examples " 104 << (buffer_size ?
"using a buffer (partial randomization)" :
"");
106 return (num_done == 0 ? 1 : 0);
107 }
catch(
const std::exception &e) {
108 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
A templated class for writing objects to an archive or script file; see The Table concept...
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...
#define KALDI_ASSERT(cond)
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)