nnet3-merge-egs.cc
Go to the documentation of this file.
1 // nnet3bin/nnet3-merge-egs.cc
2 
3 // Copyright 2012-2015 Johns Hopkins University (author: Daniel Povey)
4 // 2014 Vimal Manohar
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 #include "base/kaldi-common.h"
22 #include "util/common-utils.h"
23 #include "hmm/transition-model.h"
24 #include "nnet3/nnet-example.h"
26 
27 namespace kaldi {
28 namespace nnet3 {
29 // returns the number of indexes/frames in the NnetIo with output name
30 // including string "output" as part of its name in the eg.
31 // e.g. output-0, output-xent
33  for (size_t i = 0; i < eg.io.size(); i++)
34  if (eg.io[i].name.find("output") != std::string::npos)
35  return eg.io[i].indexes.size();
36  return 1; // Suppress compiler warning.
37 }
38 
39 }
40 }
41 
42 int main(int argc, char *argv[]) {
43  try {
44  using namespace kaldi;
45  using namespace kaldi::nnet3;
46  typedef kaldi::int32 int32;
47  typedef kaldi::int64 int64;
48 
49  const char *usage =
50  "This copies nnet training examples from input to output, but while doing so it\n"
51  "merges many NnetExample objects into one, forming a minibatch consisting of a\n"
52  "single NnetExample.\n"
53  "\n"
54  "Usage: nnet3-merge-egs [options] <egs-rspecifier> <egs-wspecifier>\n"
55  "e.g.\n"
56  "nnet3-merge-egs --minibatch-size=512 ark:1.egs ark:- | nnet3-train-simple ... \n"
57  "See also nnet3-copy-egs\n";
58 
59  ParseOptions po(usage);
60 
61  ExampleMergingConfig merging_config;
62  merging_config.Register(&po);
63 
64  po.Read(argc, argv);
65 
66  if (po.NumArgs() != 2) {
67  po.PrintUsage();
68  exit(1);
69  }
70 
71  std::string examples_rspecifier = po.GetArg(1),
72  examples_wspecifier = po.GetArg(2);
73 
74  merging_config.ComputeDerived();
75 
76  SequentialNnetExampleReader example_reader(examples_rspecifier);
77  NnetExampleWriter example_writer(examples_wspecifier);
78 
79  ExampleMerger merger(merging_config, &example_writer);
80 
81  for (; !example_reader.Done(); example_reader.Next()) {
82  const NnetExample &cur_eg = example_reader.Value();
83  merger.AcceptExample(new NnetExample(cur_eg));
84  }
85  // the merger itself prints the necessary diagnostics.
86  merger.Finish();
87  return merger.ExitStatus();
88  } catch(const std::exception &e) {
89  std::cerr << e.what() << '\n';
90  return -1;
91  }
92 }
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
Definition: nnet-example.h:111
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void AcceptExample(NnetExample *a)
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...
Definition: kaldi-table.h:368
kaldi::int32 int32
This class is responsible for arranging examples in groups that have the same strucure (i...
int main(int argc, char *argv[])
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
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).
int32 NumOutputIndexes(const NnetExample &eg)
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116