copy-post.cc
Go to the documentation of this file.
1 // bin/copy-post.cc
2 
3 // Copyright 2011-2012 Johns Hopkins University (Author: Daniel Povey) Chao Weng
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 "hmm/posterior.h"
24 
25 
26 int main(int argc, char *argv[]) {
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
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
void Register(const std::string &name, bool *ptr, const std::string &doc)
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
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int main(int argc, char *argv[])
Definition: copy-post.cc:26
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void ScalePosterior(BaseFloat scale, Posterior *post)
Scales the BaseFloat (weight) element in the posterior entries.
Definition: posterior.cc:218
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_LOG
Definition: kaldi-error.h:153