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.");
53 if (po.NumArgs() != 2) {
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...
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(std::ostream &os, bool binary) const
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...
This struct is used to store the information we need for discriminative training (MMI or MPE)...
#define KALDI_ASSERT(cond)
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)