show-transitions.cc File Reference
#include "hmm/transition-model.h"
#include "fst/fstlib.h"
#include "util/common-utils.h"
Include dependency graph for show-transitions.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 show-transitions.cc.

References ParseOptions::GetArg(), ParseOptions::GetOptArg(), rnnlm::i, KALDI_ERR, ParseOptions::NumArgs(), TransitionModel::Print(), ParseOptions::PrintUsage(), ParseOptions::Read(), Vector< Real >::Read(), kaldi::ReadKaldiObject(), and Input::Stream().

26  {
27  try {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30  using fst::SymbolTable;
31  using fst::VectorFst;
32  using fst::StdArc;
33 
34  const char *usage =
35  "Print debugging info from transition model, in human-readable form\n"
36  "Usage: show-transitions <phones-symbol-table> <transition/model-file> [<occs-file>]\n"
37  "e.g.: \n"
38  " show-transitions phones.txt 1.mdl 1.occs\n";
39 
40  ParseOptions po(usage);
41 
42  po.Read(argc, argv);
43 
44  if (po.NumArgs() < 2 || po.NumArgs() > 3) {
45  po.PrintUsage();
46  exit(1);
47  }
48 
49  std::string phones_symtab_filename = po.GetArg(1),
50  transition_model_filename = po.GetArg(2),
51  accumulator_filename = po.GetOptArg(3);
52 
53 
54  fst::SymbolTable *syms = fst::SymbolTable::ReadText(phones_symtab_filename);
55  if (!syms)
56  KALDI_ERR << "Could not read symbol table from file "
57  << phones_symtab_filename;
58  std::vector<std::string> names(syms->NumSymbols());
59  for (size_t i = 0; i < syms->NumSymbols(); i++)
60  names[i] = syms->Find(i);
61 
62  TransitionModel trans_model;
63  ReadKaldiObject(transition_model_filename, &trans_model);
64 
65  Vector<double> occs;
66  if (accumulator_filename != "") {
67  bool binary_in;
68  Input ki(accumulator_filename, &binary_in);
69  occs.Read(ki.Stream(), binary_in);
70  }
71 
72  trans_model.Print(std::cout,
73  names,
74  (accumulator_filename != "" ? &occs : NULL));
75 
76  delete syms;
77  } catch(const std::exception &e) {
78  std::cerr << e.what();
79  return -1;
80  }
81 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::StdArc StdArc
kaldi::int32 int32
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
void Print(std::ostream &os, const std::vector< std::string > &phone_names, const Vector< double > *occs=NULL)
Print will print the transition model in a human-readable way, for purposes of human inspection...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
#define KALDI_ERR
Definition: kaldi-error.h:147
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.