logistic-regression-copy.cc File Reference
Include dependency graph for logistic-regression-copy.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 logistic-regression-copy.cc.

References ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), kaldi::PrintableWxfilename(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), LogisticRegression::ScalePriors(), and kaldi::WriteKaldiObject().

26  {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29  try {
30  const char *usage =
31  "Copy a logistic-regression model, possibly changing the binary mode;\n"
32  "also supports the --scale-priors option which can scale the prior probabilities\n"
33  "the model assigns to different classes (e.g., you can remove the effect of\n"
34  "unbalanced training data by scaling by the inverse of the class priors in the\n"
35  "training data)\n"
36  "Usage: logistic-regression-copy [options] <model-in> <model-out>\n"
37  "e.g.: echo '[ 2.6 1.7 3.9 1.24 7.5 ]' | logistic-regression-copy --scale-priors=- \\\n"
38  " 1.model scaled_priors.mdl\n";
39 
40  ParseOptions po(usage);
41 
42  bool binary = true;
43  std::string scale_priors_rxfilename;
44 
45  po.Register("binary", &binary, "Write output in binary mode");
46  po.Register("scale-priors", &scale_priors_rxfilename, "(extended) filename for file "
47  "containing a vector of prior-scales (e.g. inverses of training priors)");
48 
49  po.Read(argc, argv);
50 
51  if (po.NumArgs() != 2) {
52  po.PrintUsage();
53  exit(1);
54  }
55 
56  std::string model_rxfilename = po.GetArg(1),
57  model_wxfilename = po.GetArg(2);
58 
59 
60  LogisticRegression model;
61  ReadKaldiObject(model_rxfilename, &model);
62 
63  if (scale_priors_rxfilename != "") {
64  Vector<BaseFloat> prior_scales;
65  ReadKaldiObject(scale_priors_rxfilename, &prior_scales);
66  model.ScalePriors(prior_scales);
67  }
68 
69  WriteKaldiObject(model, model_wxfilename, binary);
70 
71  KALDI_LOG << "Wrote model to " << PrintableWxfilename(model_wxfilename);
72  return 0;
73  } catch(const std::exception &e) {
74  std::cerr << e.what();
75  return -1;
76  }
77 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
kaldi::int32 int32
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void ScalePriors(const Vector< BaseFloat > &prior_scales)
A class representing a vector.
Definition: kaldi-vector.h:406
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:73
#define KALDI_LOG
Definition: kaldi-error.h:153