Blame view

src/sgmm2bin/sgmm2-info.cc 4.16 KB
8dcb6dfcb   Yannick Estève   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  // sgmm2bin/sgmm2-info.cc
  
  // Copyright 2012  Arnab Ghoshal  Johns Hopkins University (author: Daniel Povey)
  
  // See ../../COPYING for clarification regarding multiple authors
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //  http://www.apache.org/licenses/LICENSE-2.0
  //
  // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  // MERCHANTABLITY OR NON-INFRINGEMENT.
  // See the Apache 2 License for the specific language governing permissions and
  // limitations under the License.
  
  #include <iomanip>
  
  #include "base/kaldi-common.h"
  #include "util/common-utils.h"
  #include "sgmm2/am-sgmm2.h"
  #include "hmm/transition-model.h"
  
  
  int main(int argc, char *argv[]) {
    try {
      using namespace kaldi;
      typedef kaldi::int32 int32;
      const char *usage =
          "Print various information about an SGMM.
  "
          "Usage: sgmm2-info [options] <model-in> [model-in2 ... ]
  ";
  
      bool sgmm_detailed = false;
      bool trans_detailed = false;
  
      ParseOptions po(usage);
      po.Register("sgmm2-detailed", &sgmm_detailed,
                  "Print detailed information about substates.");
      po.Register("trans-detailed", &trans_detailed,
                  "Print detailed information about transition model.");
  
      po.Read(argc, argv);
      if (po.NumArgs() < 1) {
        po.PrintUsage();
        exit(1);
      }
  
      for (int i = 1, max = po.NumArgs(); i <= max; ++i) {
        std::string model_in_filename = po.GetArg(i);
        AmSgmm2 am_sgmm;
        TransitionModel trans_model;
        {
          bool binary;
          Input ki(model_in_filename, &binary);
          trans_model.Read(ki.Stream(), binary);
          am_sgmm.Read(ki.Stream(), binary);
        }
  
        {
          using namespace std;
          cout.setf(ios::left);
          cout << "
  Model file: " << model_in_filename << endl;
          cout << " SGMM information:
  "
            << setw(40) << "  # of HMM states" << am_sgmm.NumPdfs() << endl
            << setw(40) << "  # of Gaussians per state" << am_sgmm.NumGauss() << endl
            << setw(40) << "  Dimension of phone vector space"
            << am_sgmm.PhoneSpaceDim() << endl
            << setw(40) << "  Dimension of speaker vector space"
            << am_sgmm.SpkSpaceDim() << endl
            << setw(40) << "  Dimension of feature vectors"
               << am_sgmm.FeatureDim() << endl;
          int32 total_mixweights = 0;
          for (int32 j2 = 0; j2 < am_sgmm.NumPdfs(); j2++) {
            total_mixweights += am_sgmm.NumSubstatesForPdf(j2);
            if (sgmm_detailed) {
              cout << "  # of substates for state " << setw(13) << j2
                   << am_sgmm.NumSubstatesForPdf(j2) << endl;
            }
          }
          cout << setw(40) << "  Total # of mixture weights " << total_mixweights << endl;
          int32 total_groups = am_sgmm.NumGroups();
          cout << setw(40) << "  Total # of groups of pdfs " << total_groups << endl;
          int32 total_substates = 0;
          for (int32 j1 = 0; j1 < am_sgmm.NumGroups(); j1++) {
            total_substates += am_sgmm.NumSubstatesForGroup(j1);
          }
          cout << setw(40) << "  Total # of substates " << total_substates << endl;        
          cout << "
  Transition model information:
  "
               << setw(40) << " # of HMM states" << trans_model.NumPdfs() << endl
               << setw(40) << " # of transition states"
               << trans_model.NumTransitionStates() << endl;
            int32 total_indices = 0;
            for (int32 s = 0; s < trans_model.NumTransitionStates(); s++) {
              total_indices += trans_model.NumTransitionIndices(s);
              if (trans_detailed) {
                cout << "  # of transition ids for state " << setw(8) << s
                     << trans_model.NumTransitionIndices(s) << endl;
              }
            }
            cout << setw(40) << "  Total # of transition ids " << total_indices
                 << endl;
        }
      }
  
      return 0;
    } catch(const std::exception &e) {
      std::cerr << e.what();
      return -1;
    }
  }