copy-gselect.cc
Go to the documentation of this file.
1 // bin/copy-gselect.cc
2 
3 // Copyright 2009-2011 Saarland University; Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #include "base/kaldi-common.h"
22 #include "util/common-utils.h"
23 #include "gmm/diag-gmm.h"
24 #include "hmm/transition-model.h"
25 
26 int main(int argc, char *argv[]) {
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 }
80 
81 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
#define KALDI_LOG
Definition: kaldi-error.h:153
int main(int argc, char *argv[])
Definition: copy-gselect.cc:26