All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
remove-mean.cc File Reference
Include dependency graph for remove-mean.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 remove-mean.cc.

References VectorBase< Real >::AddRowSumMat(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), rnnlm::i, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29 
30  const char *usage =
31  "Remove mean from each feature file\n"
32  " [ for per-speaker normalization, use add-cmvn-stats and apply-cmvn ]\n"
33  "Usage: remove-mean [options] in-rspecifier out-wspecifier\n";
34 
35  ParseOptions po(usage);
36 
37  po.Read(argc, argv);
38 
39  if (po.NumArgs() != 2) {
40  po.PrintUsage();
41  exit(1);
42  }
43 
44  std::string rspecifier = po.GetArg(1);
45  std::string wspecifier = po.GetArg(2);
46 
47  BaseFloatMatrixWriter feat_writer(wspecifier);
48  SequentialBaseFloatMatrixReader feat_reader(rspecifier);
49  for (; !feat_reader.Done(); feat_reader.Next()) {
50  std::string key = feat_reader.Key();
51  Matrix<BaseFloat> feats (feat_reader.Value());
52  if (feats.NumRows() == 0) {
53  KALDI_WARN << "Empty feature matrix for key " << key;
54  continue;
55  }
56  Vector<BaseFloat> mean(feats.NumCols());
57  mean.AddRowSumMat(1.0, feats);
58  mean.Scale(1.0 / feats.NumRows());
59  for (int32 i = 0; i < feats.NumRows(); i++)
60  feats.Row(i).AddVec(-1.0, mean);
61  feat_writer.Write(key, feats);
62  }
63  return 0;
64  } catch(const std::exception &e) {
65  std::cerr << e.what();
66  return -1;
67  }
68 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
void AddRowSumMat(Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
Does *this = alpha * (sum of rows of M) + beta * *this.
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_WARN
Definition: kaldi-error.h:130