nnet3-get-egs-simple.cc File Reference
#include <sstream>
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "hmm/transition-model.h"
#include "hmm/posterior.h"
#include "nnet3/nnet-example.h"
#include "nnet3/nnet-example-utils.h"
Include dependency graph for nnet3-get-egs-simple.cc:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

void SplitArgOnEquals (const std::string &arg, std::string *name, std::string *rspecifier)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 55 of file nnet3-get-egs-simple.cc.

References ParseOptions::GetArg(), rnnlm::i, NnetExample::io, KALDI_WARN, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::SplitArgOnEquals(), and TableWriter< Holder >::Write().

55  {
56  try {
57  using namespace kaldi;
58  using namespace kaldi::nnet3;
59  typedef kaldi::int32 int32;
60  typedef kaldi::int64 int64;
61 
62  const char *usage =
63  "Get frame-by-frame examples of data for nnet3 neural network training.\n"
64  "This is like nnet3-get-egs, but does not split up its inputs into pieces\n"
65  "and allows more general generation of egs. E.g. this is usable for image\n"
66  "recognition tasks.\n"
67  "\n"
68  "Usage: nnet3-get-egs-simple [options] <name1>=<rspecifier1> "
69  "<name2>=<rspecifier2> ...\n"
70  "\n"
71  "e.g.:\n"
72  "nnet3-get-egs-simple input=scp:images.scp \\\n"
73  "output='ark,o:ali-to-post ark:labels.txt ark:- | post-to-smat --dim=10 ark:- ark:-' ark:egs.ark\n"
74  "\n"
75  "See also: nnet3-get-egs\n";
76 
77 
78  ParseOptions po(usage);
79 
80 
81  po.Read(argc, argv);
82 
83  if (po.NumArgs() < 2) {
84  po.PrintUsage();
85  exit(1);
86  }
87 
88 
89  std::string examples_wspecifier = po.GetArg(po.NumArgs());
90  NnetExampleWriter example_writer(examples_wspecifier);
91 
92 
93  std::string first_name, first_reader_name;
94  SplitArgOnEquals(po.GetArg(1), &first_name, &first_reader_name);
95  SequentialGeneralMatrixReader first_reader(first_reader_name);
96 
97  std::vector<std::string> other_names;
98 
99  std::vector<RandomAccessGeneralMatrixReader*> other_readers;
100 
101  for (int32 i = 2; i < po.NumArgs(); i++) {
102  std::string name, rspecifier;
103  SplitArgOnEquals(po.GetArg(i), &name, &rspecifier);
104  other_names.push_back(name);
105  other_readers.push_back(new RandomAccessGeneralMatrixReader(rspecifier));
106  }
107 
108  int32 num_done = 0, num_err = 0;
109 
110  for (; !first_reader.Done(); first_reader.Next()) {
111  std::string key = first_reader.Key();
112  NnetExample eg;
113  const GeneralMatrix &feats = first_reader.Value();
114  int32 t = 0; // first 't' value; each row of the matrix gets
115  // its own 't' value.
116  eg.io.push_back(NnetIo(first_name, t, feats));
117  bool all_ok = true;
118  for (size_t i = 0; i < other_names.size(); i++) {
119  if (!other_readers[i]->HasKey(key)) {
120  KALDI_WARN << "Could not find input for key " << key
121  << " for io-name=" << other_names[i];
122  all_ok = false;
123  break;
124  }
125  const GeneralMatrix &other_feats = other_readers[i]->Value(key);
126  eg.io.push_back(NnetIo(other_names[i], t, other_feats));
127  }
128  if (!all_ok) {
129  num_err++;
130  } else {
131  example_writer.Write(key, eg);
132  num_done++;
133  }
134  }
135  if (num_err > 0)
136  KALDI_WARN << num_err << " utterances had errors and could "
137  "not be processed.";
138  return (num_done > 0 ? 0 : 1);
139  } catch(const std::exception &e) {
140  std::cerr << e.what() << '\n';
141  return -1;
142  }
143 }
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
This class is a wrapper that enables you to store a matrix in one of three forms: either as a Matrix<...
void SplitArgOnEquals(const std::string &arg, std::string *name, std::string *rspecifier)
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
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
#define KALDI_WARN
Definition: kaldi-error.h:150
RandomAccessTableReader< KaldiObjectHolder< GeneralMatrix > > RandomAccessGeneralMatrixReader
Definition: table-types.h:177
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116