All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
post-to-smat.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "hmm/posterior.h"
Include dependency graph for post-to-smat.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 25 of file post-to-smat.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

25  {
26  using namespace kaldi;
27  typedef kaldi::int32 int32;
28  try {
29  const char *usage =
30  "This program turns an archive of per-frame posteriors, e.g. from\n"
31  "ali-to-post | post-to-pdf-post,\n"
32  "into an archive of SparseMatrix. This is just a format transformation.\n"
33  "This may not make sense if the indexes in question are one-based (at least,\n"
34  "you'd have to increase the dimension by one.\n"
35  "\n"
36  "See also: post-to-phone-post, ali-to-post, post-to-pdf-post\n"
37  "\n"
38  "Usage: post-to-smat [options] <posteriors-rspecifier> <sparse-matrix-wspecifier>\n"
39  "e.g.: post-to-smat --dim=1038 ark:- ark:-\n";
40 
41  ParseOptions po(usage);
42 
43  int32 dim = -1;
44 
45  po.Register("dim", &dim, "The num-cols in each output SparseMatrix. All "
46  "the integers in the input posteriors are expected to be \n"
47  ">= 0 and < dim. This must be specified.");
48 
49  po.Read(argc, argv);
50 
51  if (dim <= 0) {
52  KALDI_ERR << "The --dim option must be specified.";
53  }
54 
55  if (po.NumArgs() != 2) {
56  po.PrintUsage();
57  exit(1);
58  }
59 
60  std::string posteriors_rspecifier = po.GetArg(1),
61  sparse_matrix_wspecifier = po.GetArg(2);
62 
63 
64  SequentialPosteriorReader posterior_reader(posteriors_rspecifier);
65 
67  sparse_matrix_wspecifier);
68 
69  int32 num_done = 0;
70  for (; !posterior_reader.Done(); posterior_reader.Next()) {
71  const kaldi::Posterior &posterior = posterior_reader.Value();
72  // The following constructor will throw an error if there is some kind of
73  // dimension mismatch.
74  SparseMatrix<BaseFloat> smat(dim, posterior);
75  sparse_matrix_writer.Write(posterior_reader.Key(), smat);
76  num_done++;
77  }
78  KALDI_LOG << "Done converting " << num_done
79  << " posteriors into sparse matrices.";
80  } catch(const std::exception &e) {
81  std::cerr << e.what();
82  return -1;
83  }
84 }
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
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:43
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
#define KALDI_LOG
Definition: kaldi-error.h:133