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

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), rnnlm::i, KALDI_ASSERT, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29  using std::vector;
30  typedef kaldi::int32 int32;
31  const char *usage =
32  "Copy Gaussian indices for pruning, possibly making the\n"
33  "lists shorter (e.g. the --n=10 limits to the 10 best indices\n"
34  "See also gmm-gselect, fgmm-gselect\n"
35  "Usage: copy-gselect [options] <gselect-rspecifier> <gselect-wspecifier>\n";
36 
37  ParseOptions po(usage);
38  int32 num_gselect = 0;
39  std::string likelihood_wspecifier;
40  po.Register("n", &num_gselect, "Number of Gaussians to keep per frame (if nonzero)\n");
41  po.Read(argc, argv);
42 
43  if (po.NumArgs() != 2) {
44  po.PrintUsage();
45  exit(1);
46  }
47  KALDI_ASSERT(num_gselect >= 0);
48 
49  std::string gselect_rspecifier = po.GetArg(1),
50  gselect_wspecifier = po.GetArg(2);
51 
52  SequentialInt32VectorVectorReader gselect_reader(gselect_rspecifier);
53  Int32VectorVectorWriter gselect_writer(gselect_wspecifier);
54  int32 num_done = 0;
55  for (; !gselect_reader.Done(); gselect_reader.Next()) {
56  std::string utt = gselect_reader.Key();
57  if (num_gselect == 0) { // keep original size.
58  gselect_writer.Write(utt, gselect_reader.Value());
59  } else {
60  vector<vector<int32> > gselect(gselect_reader.Value());
61  for (size_t i = 0; i < gselect.size(); i++)
62  if (static_cast<int32>(gselect[i].size()) > num_gselect)
63  gselect[i].resize(num_gselect); // keep 1st n elements.
64  gselect_writer.Write(utt, gselect);
65  }
66  num_done++;
67  }
68  if (num_gselect == 0)
69  KALDI_LOG << "Copied " << num_done << " gselect objects ";
70  else
71  KALDI_LOG << "Copied " << num_done << " gselect objects, "
72  << " limiting sizes to " << num_gselect;
73  if (num_done != 0) return 0;
74  else return 1;
75  } catch(const std::exception &e) {
76  std::cerr << e.what();
77  return -1;
78  }
79 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
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
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153