292 using namespace kaldi;
295 typedef kaldi::int64 int64;
298 "Copy examples (single frames or fixed-size groups of frames) for neural\n" 299 "network training, possibly changing the binary mode. Supports multiple wspecifiers, in\n" 300 "which case it will write the examples round-robin to the outputs.\n" 302 "Usage: nnet3-copy-egs [options] <egs-rspecifier> <egs-wspecifier1> [<egs-wspecifier2> ...]\n" 305 "nnet3-copy-egs ark:train.egs ark,t:text.egs\n" 307 "nnet3-copy-egs ark:train.egs ark:1.egs ark:2.egs\n" 308 "See also: nnet3-subset-egs, nnet3-get-egs, nnet3-merge-egs, nnet3-shuffle-egs\n";
311 int32 srand_seed = 0;
312 int32 frame_shift = 0;
318 int32 left_context = -1, right_context = -1;
322 std::string frame_str,
323 eg_weight_rspecifier, eg_output_name_rspecifier;
326 po.Register(
"random", &random,
"If true, will write frames to output " 327 "archives randomly, not round-robin.");
328 po.Register(
"frame-shift", &frame_shift,
"Allows you to shift time values " 329 "in the supervision data (excluding iVector data). Only really " 330 "useful in clockwork topologies (i.e. any topology for which " 331 "modulus != 1). Shifting is done after any frame selection.");
332 po.Register(
"keep-proportion", &keep_proportion,
"If <1.0, this program will " 333 "randomly keep this proportion of the input samples. If >1.0, it will " 334 "in expectation copy a sample this many times. It will copy it a number " 335 "of times equal to floor(keep-proportion) or ceil(keep-proportion).");
336 po.Register(
"srand", &srand_seed,
"Seed for random number generator " 337 "(only relevant if --random=true or --keep-proportion != 1.0)");
338 po.Register(
"frame", &frame_str,
"This option can be used to select a single " 339 "frame from each multi-frame example. Set to a number 0, 1, etc. " 340 "to select a frame with a given index, or 'random' to select a " 342 po.Register(
"left-context", &left_context,
"Can be used to truncate the " 343 "feature left-context that we output.");
344 po.Register(
"right-context", &right_context,
"Can be used to truncate the " 345 "feature right-context that we output.");
346 po.Register(
"weights", &eg_weight_rspecifier,
347 "Rspecifier indexed by the key of egs, providing a weight by " 348 "which we will scale the supervision matrix for that eg. " 349 "Used in multilingual training.");
350 po.Register(
"outputs", &eg_output_name_rspecifier,
351 "Rspecifier indexed by the key of egs, providing a string-valued " 352 "output name, e.g. 'output-0'. If provided, the NnetIo with " 353 "name 'output' will be renamed to the provided name. Used in " 354 "multilingual training.");
359 if (po.NumArgs() < 2) {
364 std::string examples_rspecifier = po.GetArg(1);
373 int32 num_outputs = po.NumArgs() - 1;
374 std::vector<NnetExampleWriter*> example_writers(num_outputs);
375 for (int32
i = 0;
i < num_outputs;
i++)
379 int64 num_read = 0, num_written = 0, num_err = 0;
380 for (; !example_reader.Done(); example_reader.Next(), num_read++) {
381 const std::string &key = example_reader.Key();
386 if (!eg_weight_rspecifier.empty()) {
388 if (!egs_weight_reader.HasKey(key)) {
389 KALDI_WARN <<
"No weight for example key " << key;
393 weight = egs_weight_reader.Value(key);
397 std::string new_output_name;
398 if (!eg_output_name_rspecifier.empty()) {
399 if (!output_name_reader.HasKey(key)) {
400 KALDI_WARN <<
"No new output-name for example key " << key;
404 new_output_name = output_name_reader.Value(key);
406 for (int32 c = 0; c <
count; c++) {
407 int32 index = (random ?
Rand() : num_written) % num_outputs;
408 if (frame_str ==
"" && left_context == -1 && right_context == -1 &&
410 if (!new_output_name.empty() && c == 0)
412 example_writers[index]->Write(key, eg);
417 frame_shift, &eg_modified)) {
418 if (!new_output_name.empty())
422 example_writers[index]->Write(key, eg_modified);
429 for (int32
i = 0;
i < num_outputs;
i++)
430 delete example_writers[
i];
431 KALDI_LOG <<
"Read " << num_read <<
" neural-network training examples, wrote " 432 << num_written <<
", " 433 << num_err <<
" examples had errors.";
434 return (num_written == 0 ? 1 : 0);
435 }
catch(
const std::exception &e) {
436 std::cerr << e.what() <<
'\n';
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Allows random access to a collection of objects in 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...
void ScaleSupervisionWeight(BaseFloat weight, NnetExample *eg)
void RenameOutputs(const std::string &new_name, NnetExample *eg)
int32 GetCount(double expected_count)
int Rand(struct RandomState *state)
TableWriter< KaldiObjectHolder< NnetExample > > NnetExampleWriter
bool SelectFromExample(const NnetExample &eg, std::string frame_str, int32 left_context, int32 right_context, int32 frame_shift, NnetExample *eg_out)
This function is responsible for possibly selecting one frame from multiple supervised frames...