All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fgmm-global-merge.cc File Reference
#include "util/common-utils.h"
#include "gmm/full-gmm.h"
#include "gmm/mle-full-gmm.h"
Include dependency graph for fgmm-global-merge.cc:

Go to the source code of this file.

Namespaces

 kaldi
 Relabels neural network egs with the read pdf-id alignments.
 

Functions

void MergeFullGmm (const FullGmm &src, FullGmm *dst)
 merges GMMs by appending Gaussians in "src" to "dst". More...
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 65 of file fgmm-global-merge.cc.

References ParseOptions::GetArg(), rnnlm::i, KALDI_LOG, kaldi::MergeFullGmm(), ParseOptions::NumArgs(), FullGmm::NumGauss(), ParseOptions::PrintUsage(), ParseOptions::Read(), FullGmm::Read(), ParseOptions::Register(), Output::Stream(), Input::Stream(), and kaldi::WriteKaldiObject().

65  {
66  try {
67  using namespace kaldi;
68  typedef kaldi::int32 int32;
69 
70  const char *usage =
71  "Combine a number of GMMs into a larger GMM, with #Gauss = \n"
72  " sum(individual #Gauss)). Output full GMM, and a text file with\n"
73  " sizes of each individual GMM.\n"
74  "Usage: fgmm-global-merge [options] fgmm-out sizes-file-out fgmm-in1 fgmm-in2 ...\n";
75 
76  bool binary = true;
77  ParseOptions po(usage);
78  po.Register("binary", &binary, "Write output in binary mode");
79  po.Read(argc, argv);
80 
81  if (po.NumArgs() < 4) {
82  po.PrintUsage();
83  exit(1);
84  }
85 
86  std::string fgmm_out_filename = po.GetArg(1),
87  sizes_out_filename = po.GetArg(2);
88 
89  FullGmm fgmm;
90  Output sizes_ko(sizes_out_filename, false); // false == not binary.
91 
92  for (int i = 3, max = po.NumArgs(); i <= max; i++) {
93  std::string stats_in_filename = po.GetArg(i);
94  bool binary_read;
95  Input ki(stats_in_filename, &binary_read);
96  if (i==3) {
97  fgmm.Read(ki.Stream(), binary_read);
98  sizes_ko.Stream() << fgmm.NumGauss() << ' ';
99  } else {
100  FullGmm fgmm2;
101  fgmm2.Read(ki.Stream(), binary_read);
102  sizes_ko.Stream() << fgmm2.NumGauss() << ' ';
103  MergeFullGmm(fgmm2, &fgmm);
104  }
105  }
106  sizes_ko.Stream() << "\n";
107 
108  // Write out the model
109  WriteKaldiObject(fgmm, fgmm_out_filename, binary);
110  KALDI_LOG << "Written merged GMM to " << fgmm_out_filename;
111  } catch(const std::exception &e) {
112  std::cerr << e.what() << '\n';
113  return -1;
114  }
115 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
int32 NumGauss() const
Returns the number of mixture components in the GMM.
Definition: full-gmm.h:58
Definition for Gaussian Mixture Model with full covariances.
Definition: full-gmm.h:40
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void MergeFullGmm(const FullGmm &src, FullGmm *dst)
merges GMMs by appending Gaussians in "src" to "dst".
void Read(std::istream &is, bool binary)
Definition: full-gmm.cc:813
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:133