post-to-pdf-post.cc
Go to the documentation of this file.
1 // bin/post-to-pdf-post.cc
2 
3 // Copyright 2012-2013 Johns Hopkins University (Author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #include "base/kaldi-common.h"
22 #include "util/common-utils.h"
23 #include "gmm/am-diag-gmm.h"
24 #include "hmm/transition-model.h"
25 #include "hmm/hmm-utils.h"
26 #include "hmm/posterior.h"
27 
28 int main(int argc, char *argv[]) {
29  using namespace kaldi;
30  typedef kaldi::int32 int32;
31  try {
32  const char *usage =
33  "This program turns per-frame posteriors, which have transition-ids as\n"
34  "the integers, into pdf-level posteriors\n"
35  "See also: post-to-phone-post, post-to-weights, get-post-on-ali\n"
36  "\n"
37  "Usage: post-to-pdf-post [options] <model-file> <posteriors-rspecifier> <posteriors-wspecifier>\n"
38  "e.g.: post-to-pdf-post 1.mdl ark:- ark:-\n";
39 
40  ParseOptions po(usage);
41 
42  po.Read(argc, argv);
43 
44  if (po.NumArgs() != 3) {
45  po.PrintUsage();
46  exit(1);
47  }
48 
49  std::string model_rxfilename = po.GetArg(1),
50  posteriors_rspecifier = po.GetArg(2),
51  posteriors_wspecifier = po.GetArg(3);
52 
53  TransitionModel trans_model;
54  {
55  bool binary_in;
56  Input ki(model_rxfilename, &binary_in);
57  trans_model.Read(ki.Stream(), binary_in);
58  }
59 
60  int32 num_done = 0;
61  SequentialPosteriorReader posterior_reader(posteriors_rspecifier);
62  PosteriorWriter posterior_writer(posteriors_wspecifier);
63 
64  for (; !posterior_reader.Done(); posterior_reader.Next()) {
65  const kaldi::Posterior &posterior = posterior_reader.Value();
66  kaldi::Posterior pdf_posterior;
67  ConvertPosteriorToPdfs(trans_model, posterior, &pdf_posterior);
68  posterior_writer.Write(posterior_reader.Key(), pdf_posterior);
69  num_done++;
70  }
71  KALDI_LOG << "Done converting posteriors to pdf-level posteriors for "
72  << num_done << " utterances.";
73 
74  } catch(const std::exception &e) {
75  std::cerr << e.what();
76  return -1;
77  }
78 }
79 
80 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
void Write(const std::string &key, const T &value) const
std::istream & Stream()
Definition: kaldi-io.cc:826
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
int main(int argc, char *argv[])
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
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void ConvertPosteriorToPdfs(const TransitionModel &tmodel, const Posterior &post_in, Posterior *post_out)
Converts a posterior over transition-ids to be a posterior over pdf-ids.
Definition: posterior.cc:322
#define KALDI_LOG
Definition: kaldi-error.h:153