copy-post.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "hmm/posterior.h"
Include dependency graph for copy-post.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 26 of file copy-post.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), kaldi::ScalePosterior(), 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  "Copy archives of posteriors, with optional scaling\n"
33  "\n"
34  "Usage: copy-post <post-rspecifier> <post-wspecifier>\n"
35  "See also: post-to-weights, scale-post, sum-post, weight-post ...\n";
36 
37  BaseFloat scale = 1.0;
38  ParseOptions po(usage);
39  po.Register("scale", &scale, "Scale for posteriors");
40  po.Read(argc, argv);
41 
42  if (po.NumArgs() != 2) {
43  po.PrintUsage();
44  exit(1);
45  }
46 
47  std::string post_rspecifier = po.GetArg(1),
48  post_wspecifier = po.GetArg(2);
49 
50  kaldi::SequentialPosteriorReader posterior_reader(post_rspecifier);
51  kaldi::PosteriorWriter posterior_writer(post_wspecifier);
52 
53  int32 num_done = 0;
54 
55  for (; !posterior_reader.Done(); posterior_reader.Next()) {
56  std::string key = posterior_reader.Key();
57 
58  if (scale != 1.0) {
59  kaldi::Posterior posterior = posterior_reader.Value();
60  ScalePosterior(scale, &posterior);
61  posterior_writer.Write(key, posterior);
62  } else {
63  posterior_writer.Write(key, posterior_reader.Value());
64  }
65  num_done++;
66  }
67  KALDI_LOG << "Done copying " << num_done << " posteriors.";
68  return (num_done != 0 ? 0 : 1);
69  } catch(const std::exception &e) {
70  std::cerr << e.what();
71  return -1;
72  }
73 }
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
float BaseFloat
Definition: kaldi-types.h:29
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
void ScalePosterior(BaseFloat scale, Posterior *post)
Scales the BaseFloat (weight) element in the posterior entries.
Definition: posterior.cc:218
#define KALDI_LOG
Definition: kaldi-error.h:153