feat-to-post.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "hmm/posterior.h"
Include dependency graph for feat-to-post.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Converts features into posterior format, which is the generic format of NN training targets in 'nnet1'. More...
 

Function Documentation

◆ main()

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

Converts features into posterior format, which is the generic format of NN training targets in 'nnet1'.

Definition at line 27 of file feat-to-post.cc.

References rnnlm::d, SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ASSERT, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

27  {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30  try {
31  const char *usage =
32  "Convert features into posterior format, which is the generic format \n"
33  "of NN training targets in Karel's nnet1 tools.\n"
34  "(speed is not an issue for reasonably low NN-output dimensions)\n"
35  "Usage: feat-to-post [options] feat-rspecifier posteriors-wspecifier\n"
36  "e.g.:\n"
37  " feat-to-post scp:feats.scp ark:feats.post\n";
38 
39  ParseOptions po(usage);
40 
41  po.Read(argc, argv);
42 
43  if (po.NumArgs() != 2) {
44  po.PrintUsage();
45  exit(1);
46  }
47 
48  std::string feats_rspecifier = po.GetArg(1);
49  std::string posteriors_wspecifier = po.GetArg(2);
50 
51  int32 num_done = 0;
52  SequentialBaseFloatMatrixReader feats_reader(feats_rspecifier);
53  PosteriorWriter posterior_writer(posteriors_wspecifier);
54 
55  for (; !feats_reader.Done(); feats_reader.Next()) {
56  num_done++;
57  const Matrix<BaseFloat> &mat = feats_reader.Value();
58  int32 num_frames = mat.NumRows(),
59  num_dims = mat.NumCols();
60  // Posterior is vector<vector<pair<int32, BaseFloat> > >
61  Posterior post(num_frames);
62  // Fill posterior with matrix values,
63  for (int32 f = 0; f < num_frames; f++) {
64  for (int32 d = 0; d < num_dims; d++) {
65  post[f].push_back(std::make_pair(d, mat(f, d)));
66  }
67  KALDI_ASSERT(post[f].size() == num_dims);
68  }
69  // Store
70  posterior_writer.Write(feats_reader.Key(), post);
71  }
72  KALDI_LOG << "Converted " << num_done << " alignments.";
73  return (num_done != 0 ? 0 : 1);
74  } catch(const std::exception &e) {
75  std::cerr << e.what();
76  return -1;
77  }
78 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
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_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
#define KALDI_LOG
Definition: kaldi-error.h:153