All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
add-deltas-sdc.cc File Reference
Include dependency graph for add-deltas-sdc.cc:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 26 of file add-deltas-sdc.cc.

References kaldi::ComputeShiftedDeltas(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), ShiftedDeltaFeaturesOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29 
30  const char *usage =
31  "Add shifted delta cepstra (typically to raw mfcc or plp features\n"
32  "Usage: add-deltas-sdc [options] in-rspecifier out-wspecifier\n";
34  int32 truncate = 0;
35  ParseOptions po(usage);
36  po.Register("truncate", &truncate, "If nonzero, first truncate features to this dimension.");
37  opts.Register(&po);
38 
39  po.Read(argc, argv);
40 
41  if (po.NumArgs() != 2) {
42  po.PrintUsage();
43  exit(1);
44  }
45 
46  std::string rspecifier = po.GetArg(1);
47  std::string wspecifier = po.GetArg(2);
48 
49  BaseFloatMatrixWriter feat_writer(wspecifier);
50  SequentialBaseFloatMatrixReader feat_reader(rspecifier);
51  for (; !feat_reader.Done(); feat_reader.Next()) {
52  std::string key = feat_reader.Key();
53  const Matrix<BaseFloat> &feats = feat_reader.Value();
54 
55  if (feats.NumRows() == 0) {
56  KALDI_WARN << "Empty feature matrix for key " << key;
57  continue;
58  }
59  Matrix<BaseFloat> new_feats;
60  if (truncate != 0) {
61  if (truncate > feats.NumCols())
62  KALDI_ERR << "Cannot truncate features as dimension " << feats.NumCols()
63  << " is smaller than truncation dimension.";
64  SubMatrix<BaseFloat> feats_sub(feats, 0, feats.NumRows(), 0, truncate);
65  ComputeShiftedDeltas(opts, feats_sub, &new_feats);
66  } else
67  ComputeShiftedDeltas(opts, feats, &new_feats);
68  feat_writer.Write(key, new_feats);
69  }
70  return 0;
71  } catch(const std::exception &e) {
72  std::cerr << e.what();
73  return -1;
74  }
75 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
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_ERR
Definition: kaldi-error.h:127
void ComputeShiftedDeltas(const ShiftedDeltaFeaturesOptions &delta_opts, const MatrixBase< BaseFloat > &input_features, Matrix< BaseFloat > *output_features)
#define KALDI_WARN
Definition: kaldi-error.h:130
MatrixIndexT NumRows() const
Returns number of rows (or zero for emtpy matrix).
Definition: kaldi-matrix.h:58
MatrixIndexT NumCols() const
Returns number of columns (or zero for emtpy matrix).
Definition: kaldi-matrix.h:61
Sub-matrix representation.
Definition: kaldi-matrix.h:908