ivector-copy-plda.cc
Go to the documentation of this file.
1 // ivectorbin/ivector-copy-plda.cc
2 
3 // Copyright 2013 Daniel Povey
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 "ivector/plda.h"
24 
25 
26 int main(int argc, char *argv[]) {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29  try {
30  const char *usage =
31  "Copy a PLDA object, possibly applying smoothing to the within-class\n"
32  "covariance\n"
33  "\n"
34  "Usage: ivector-copy-plda <plda-in> <plda-out>\n"
35  "e.g.: ivector-copy-plda --smoothing=0.1 plda plda.smooth0.1\n";
36 
37  ParseOptions po(usage);
38 
39  BaseFloat smoothing = 0.0;
40  bool binary = true;
41  po.Register("smoothing", &smoothing, "Factor used in smoothing within-class "
42  "covariance (add this factor times between-class covar)");
43  po.Register("binary", &binary, "Write output in binary mode");
44 
45  PldaConfig plda_config;
46  plda_config.Register(&po);
47 
48  po.Read(argc, argv);
49 
50  if (po.NumArgs() != 2) {
51  po.PrintUsage();
52  exit(1);
53  }
54 
55  std::string plda_rxfilename = po.GetArg(1),
56  plda_wxfilename = po.GetArg(2);
57 
58  Plda plda;
59  ReadKaldiObject(plda_rxfilename, &plda);
60  if (smoothing != 0.0)
61  plda.SmoothWithinClassCovariance(smoothing);
62  WriteKaldiObject(plda, plda_wxfilename, binary);
63 
64  return 0;
65  } catch(const std::exception &e) {
66  std::cerr << e.what();
67  return -1;
68  }
69 }
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].
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void SmoothWithinClassCovariance(double smoothing_factor)
This function smooths the within-class covariance by adding to it, smoothing_factor (e...
Definition: plda.cc:195
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int main(int argc, char *argv[])
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void Register(OptionsItf *opts)
Definition: plda.h:56
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257