26 int main(
int argc,
char *argv[]) {
28 using namespace kaldi;
30 typedef kaldi::int64 int64;
33 "Sum two sets of posteriors for each utterance, e.g. useful in fMMI.\n" 34 "To take the difference of posteriors, use e.g. --scale2=-1.0\n" 36 "Usage: sum-post <post-rspecifier1> <post-rspecifier2> <post-wspecifier>\n";
40 bool drop_frames =
false;
42 po.
Register(
"scale1", &scale1,
"Scale for first set of posteriors");
43 po.
Register(
"scale2", &scale2,
"Scale for second set of posteriors");
44 po.
Register(
"merge", &merge,
"If true, merge posterior entries for " 45 "same transition-id (canceling positive and negative parts)");
46 po.
Register(
"zero-if-disjoint", &drop_frames,
"If true, zero " 47 "posteriors on all frames when the two sets of posteriors are " 48 "disjoint (this option for back-compatibility only; use " 50 po.
Register(
"drop-frames", &drop_frames,
"If true, zero " 51 "posteriors on all frames when the two sets of posteriors are " 60 std::string post_rspecifier1 = po.
GetArg(1),
61 post_rspecifier2 = po.
GetArg(2),
62 post_wspecifier = po.
GetArg(3);
68 int32 num_done = 0, num_err = 0;
69 int64 num_frames_tot = 0, num_frames_disjoint = 0;
71 for (; !posterior_reader1.
Done(); posterior_reader1.
Next()) {
72 std::string key = posterior_reader1.
Key();
74 if (!posterior_reader2.
HasKey(key)) {
75 KALDI_WARN <<
"Second set of posteriors has nothing for key " 76 << key <<
", producing no output.";
81 if (posterior2.size() != posterior1.size()) {
82 KALDI_WARN <<
"Posteriors have mismatched sizes " << posterior1.size()
83 <<
" vs. " << posterior2.size() <<
" for key " << key;
92 drop_frames, &posterior_out);
93 num_frames_tot +=
static_cast<int64
>(posterior1.size());
94 posterior_writer.
Write(key, posterior_out);
97 KALDI_LOG <<
"Processed " << num_frames_tot <<
" frames; for " 98 << num_frames_disjoint <<
" frames there was no overlap, i.e. " 99 << (num_frames_disjoint * 100.0 / num_frames_tot)
100 <<
"% (e.g. numerator path not in denominator lattice)";
101 KALDI_LOG <<
"Done adding " << num_done <<
" posteriors; " << num_err
103 return (num_done != 0 ? 0 : 1);
104 }
catch(
const std::exception &e) {
105 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
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...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
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[])
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
bool HasKey(const std::string &key)
void ScalePosterior(BaseFloat scale, Posterior *post)
Scales the BaseFloat (weight) element in the posterior entries.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
int32 MergePosteriors(const Posterior &post1, const Posterior &post2, bool merge, bool drop_frames, Posterior *post)
Merge two sets of posteriors, which must have the same length.