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

References kaldi::ConvertPosteriorToPhones(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), TransitionModel::Read(), Input::Stream(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30 
31  const char *usage =
32  "Convert posteriors to phone-level posteriors\n"
33  "See also: post-to-pdf-post, post-to-weights, get-post-on-ali\n"
34  "\n"
35  "Usage: post-to-phone-post [options] <model> <post-rspecifier> <phone-post-wspecifier>\n"
36  " e.g.: post-to-phone-post --binary=false 1.mdl \"ark:ali-to-post 1.ali|\" ark,t:-\n";
37 
38  ParseOptions po(usage);
39 
40  po.Read(argc, argv);
41 
42  if (po.NumArgs() != 3) {
43  po.PrintUsage();
44  exit(1);
45  }
46 
47  std::string model_rxfilename = po.GetArg(1),
48  post_rspecifier = po.GetArg(2),
49  phone_post_wspecifier = po.GetArg(3);
50 
51  kaldi::SequentialPosteriorReader posterior_reader(post_rspecifier);
52  kaldi::PosteriorWriter posterior_writer(phone_post_wspecifier);
53 
54  TransitionModel trans_model;
55  {
56  bool binary_in;
57  Input ki(model_rxfilename, &binary_in);
58  trans_model.Read(ki.Stream(), binary_in);
59  }
60  int32 num_done = 0;
61 
62  for (; !posterior_reader.Done(); posterior_reader.Next()) {
63  const kaldi::Posterior &posterior = posterior_reader.Value();
64  kaldi::Posterior phone_posterior;
65  ConvertPosteriorToPhones(trans_model, posterior, &phone_posterior);
66  posterior_writer.Write(posterior_reader.Key(), phone_posterior);
67  num_done++;
68  }
69  KALDI_LOG << "Done converting posteriors to phone posteriors for "
70  << num_done << " utterances.";
71  return (num_done != 0 ? 0 : 1);
72  } catch(const std::exception &e) {
73  std::cerr << e.what();
74  return -1;
75  }
76 }
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
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
void ConvertPosteriorToPhones(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over phones.
Definition: posterior.cc:348
#define KALDI_LOG
Definition: kaldi-error.h:133