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

◆ main()

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 (po.NumArgs() != 2) {
52  po.PrintUsage();
53  exit(1);
54  }
55 
56  if (dim <= 0) {
57  KALDI_ERR << "The --dim option must be specified.";
58  }
59 
60 
61  std::string posteriors_rspecifier = po.GetArg(1),
62  sparse_matrix_wspecifier = po.GetArg(2);
63 
64 
65  SequentialPosteriorReader posterior_reader(posteriors_rspecifier);
66 
68  sparse_matrix_wspecifier);
69 
70  int32 num_done = 0;
71  for (; !posterior_reader.Done(); posterior_reader.Next()) {
72  const kaldi::Posterior &posterior = posterior_reader.Value();
73  // The following constructor will throw an error if there is some kind of
74  // dimension mismatch.
75  SparseMatrix<BaseFloat> smat(dim, posterior);
76  sparse_matrix_writer.Write(posterior_reader.Key(), smat);
77  num_done++;
78  }
79  KALDI_LOG << "Done converting " << num_done
80  << " posteriors into sparse matrices.";
81  } catch(const std::exception &e) {
82  std::cerr << e.what();
83  return -1;
84  }
85 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
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_ERR
Definition: kaldi-error.h:147
#define KALDI_LOG
Definition: kaldi-error.h:153