gmm-compute-likes.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "gmm/am-diag-gmm.h"
#include "hmm/transition-model.h"
#include "fstext/fstext-lib.h"
#include "base/timer.h"
Include dependency graph for gmm-compute-likes.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 30 of file gmm-compute-likes.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), rnnlm::i, rnnlm::j, KALDI_LOG, SequentialTableReader< Holder >::Key(), AmDiagGmm::LogLikelihood(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), AmDiagGmm::NumPdfs(), ParseOptions::PrintUsage(), AmDiagGmm::Read(), ParseOptions::Read(), TransitionModel::Read(), Input::Stream(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

30  {
31  try {
32  using namespace kaldi;
33  typedef kaldi::int32 int32;
34  using fst::SymbolTable;
35  using fst::VectorFst;
36  using fst::StdArc;
37 
38  const char *usage =
39  "Compute log-likelihoods from GMM-based model\n"
40  "(outputs matrices of log-likelihoods indexed by (frame, pdf)\n"
41  "Usage: gmm-compute-likes [options] model-in features-rspecifier likes-wspecifier\n";
42  ParseOptions po(usage);
43 
44  po.Read(argc, argv);
45 
46  if (po.NumArgs() != 3) {
47  po.PrintUsage();
48  exit(1);
49  }
50 
51  std::string model_in_filename = po.GetArg(1),
52  feature_rspecifier = po.GetArg(2),
53  loglikes_wspecifier = po.GetArg(3);
54 
55  AmDiagGmm am_gmm;
56  {
57  bool binary;
58  TransitionModel trans_model; // not needed.
59  Input ki(model_in_filename, &binary);
60  trans_model.Read(ki.Stream(), binary);
61  am_gmm.Read(ki.Stream(), binary);
62  }
63 
64  BaseFloatMatrixWriter loglikes_writer(loglikes_wspecifier);
65  SequentialBaseFloatMatrixReader feature_reader(feature_rspecifier);
66 
67  int32 num_done = 0;
68  for (; !feature_reader.Done(); feature_reader.Next()) {
69  std::string key = feature_reader.Key();
70  const Matrix<BaseFloat> &features (feature_reader.Value());
71  Matrix<BaseFloat> loglikes(features.NumRows(), am_gmm.NumPdfs());
72  for (int32 i = 0; i < features.NumRows(); i++) {
73  for (int32 j = 0; j < am_gmm.NumPdfs(); j++) {
74  SubVector<BaseFloat> feat_row(features, i);
75  loglikes(i, j) = am_gmm.LogLikelihood(j, feat_row);
76  }
77  }
78  loglikes_writer.Write(key, loglikes);
79  num_done++;
80  }
81 
82  KALDI_LOG << "gmm-compute-likes: computed likelihoods for " << num_done
83  << " utterances.";
84  return 0;
85  } catch(const std::exception &e) {
86  std::cerr << e.what();
87  return -1;
88  }
89 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::StdArc StdArc
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
BaseFloat LogLikelihood(const int32 pdf_index, const VectorBase< BaseFloat > &data) const
Definition: am-diag-gmm.h:108
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
int32 NumPdfs() const
Definition: am-diag-gmm.h:82
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &in_stream, bool binary)
Definition: am-diag-gmm.cc:147
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
Definition: kaldi-vector.h:501