sgmm2-gselect.cc File Reference
Include dependency graph for sgmm2-gselect.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 27 of file sgmm2-gselect.cc.

References SequentialTableReader< Holder >::Done(), AmSgmm2::GaussianSelection(), ParseOptions::GetArg(), rnnlm::i, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), MatrixBase< Real >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), TransitionModel::Read(), AmSgmm2::Read(), ParseOptions::Register(), Sgmm2GselectConfig::Register(), MatrixBase< Real >::Row(), Input::Stream(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

27  {
28  try {
29  using namespace kaldi;
30  const char *usage =
31  "Precompute Gaussian indices for SGMM training "
32  "Usage: sgmm2-gselect [options] <model-in> <feature-rspecifier> <gselect-wspecifier>\n"
33  "e.g.: sgmm2-gselect 1.sgmm \"ark:feature-command |\" ark:1.gs\n"
34  "Note: you can do the same thing by combining the programs sgmm2-write-ubm, fgmm-global-to-gmm,\n"
35  "gmm-gselect and fgmm-gselect\n";
36 
37  ParseOptions po(usage);
38  kaldi::Sgmm2GselectConfig sgmm_opts;
39  std::string preselect_rspecifier;
40  std::string likelihood_wspecifier;
41  po.Register("write-likes", &likelihood_wspecifier, "Wspecifier for likelihoods per "
42  "utterance");
43  sgmm_opts.Register(&po);
44  po.Read(argc, argv);
45 
46  if (po.NumArgs() != 3) {
47  po.PrintUsage();
48  exit(1);
49  }
50 
51  std::string model_filename = po.GetArg(1),
52  feature_rspecifier = po.GetArg(2),
53  gselect_wspecifier = po.GetArg(3);
54 
55  using namespace kaldi;
56  typedef kaldi::int32 int32;
57 
58  AmSgmm2 am_sgmm;
59  {
60  bool binary;
61  Input ki(model_filename, &binary);
62  TransitionModel trans_model;
63  trans_model.Read(ki.Stream(), binary);
64  am_sgmm.Read(ki.Stream(), binary);
65  }
66 
67  double tot_like = 0.0;
68  kaldi::int64 tot_t = 0;
69 
70  SequentialBaseFloatMatrixReader feature_reader(feature_rspecifier);
71  Int32VectorVectorWriter gselect_writer(gselect_wspecifier);
72  BaseFloatWriter likelihood_writer(likelihood_wspecifier);
73 
74  int32 num_done = 0, num_err = 0;
75  for (; !feature_reader.Done(); feature_reader.Next()) {
76  int32 tot_t_this_file = 0; double tot_like_this_file = 0;
77  std::string utt = feature_reader.Key();
78  const Matrix<BaseFloat> &mat = feature_reader.Value();
79  std::vector<std::vector<int32> > gselect_vec(mat.NumRows());
80  tot_t_this_file += mat.NumRows();
81  for (int32 i = 0; i < mat.NumRows(); i++)
82  tot_like_this_file += am_sgmm.GaussianSelection(sgmm_opts, mat.Row(i), &(gselect_vec[i]));
83 
84  gselect_writer.Write(utt, gselect_vec);
85  if (num_done % 10 == 0)
86  KALDI_LOG << "For " << num_done << "'th file, average UBM likelihood over "
87  << tot_t_this_file << " frames is "
88  << (tot_like_this_file/tot_t_this_file);
89  tot_t += tot_t_this_file;
90  tot_like += tot_like_this_file;
91 
92  if(likelihood_wspecifier != "")
93  likelihood_writer.Write(utt, tot_like_this_file);
94  num_done++;
95  }
96 
97  KALDI_LOG << "Done " << num_done << " files, " << num_err
98  << " with errors, average UBM log-likelihood is "
99  << (tot_like/tot_t) << " over " << tot_t << " frames.";
100 
101 
102  if (num_done != 0) return 0;
103  else return 1;
104  } catch(const std::exception &e) {
105  std::cerr << e.what();
106  return -1;
107  }
108 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Class for definition of the subspace Gmm acoustic model.
Definition: am-sgmm2.h:231
void Read(std::istream &is, bool binary)
Definition: am-sgmm2.cc:89
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
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
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
BaseFloat GaussianSelection(const Sgmm2GselectConfig &config, const VectorBase< BaseFloat > &data, std::vector< int32 > *gselect) const
Computes the top-scoring Gaussian indices (used for pruning of later stages of computation).
Definition: am-sgmm2.cc:1406
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
#define KALDI_LOG
Definition: kaldi-error.h:153
void Register(OptionsItf *opts)
Definition: am-sgmm2.h:129