show-transitions.cc
Go to the documentation of this file.
1 // bin/show-transitions.cc
2 //
3 // Copyright 2009-2011 Microsoft Corporation
4 // 2014 Johns Hopkins University (author: Daniel Povey)
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 #include "hmm/transition-model.h"
22 #include "fst/fstlib.h"
23 #include "util/common-utils.h"
24 
25 
26 int main(int argc, char *argv[]) {
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 }
82 
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].
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...
std::istream & Stream()
Definition: kaldi-io.cc:826
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
#define KALDI_ERR
Definition: kaldi-error.h:147
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).
int main(int argc, char *argv[])
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.
std::string GetOptArg(int param) const