ivector-adapt-plda.cc
Go to the documentation of this file.
1 // ivectorbin/ivector-adapt-plda.cc
2 
3 // Copyright 2013-2014 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  "Adapt a PLDA object using unsupervised adaptation-data iVectors from a different\n"
32  "domain to the training data.\n"
33  "\n"
34  "Usage: ivector-adapt-plda [options] <plda-in> <ivectors-rspecifier> <plda-out>\n"
35  "e.g.: ivector-adapt-plda plda ark:ivectors.ark plda.adapted\n";
36 
37  ParseOptions po(usage);
38 
39  bool binary = true;
40  po.Register("binary", &binary, "Write output in binary mode");
42  config.Register(&po);
43 
44 
45 
46  po.Read(argc, argv);
47 
48  if (po.NumArgs() != 3) {
49  po.PrintUsage();
50  exit(1);
51  }
52 
53  std::string plda_rxfilename = po.GetArg(1),
54  ivector_rspecifier = po.GetArg(2),
55  plda_wxfilename = po.GetArg(3);
56 
57  Plda plda;
58  ReadKaldiObject(plda_rxfilename, &plda);
59 
60  SequentialBaseFloatVectorReader ivector_reader(ivector_rspecifier);
61 
62  int32 num_done = 0;
64  for (; !ivector_reader.Done(); ivector_reader.Next(), num_done++)
65  adaptor.AddStats(1.0, ivector_reader.Value());
66 
67  adaptor.UpdatePlda(config, &plda);
68 
69  WriteKaldiObject(plda, plda_wxfilename, binary);
70 
71  return (num_done != 0 ? 0 : 1);
72  } catch(const std::exception &e) {
73  std::cerr << e.what();
74  return -1;
75  }
76 }
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].
int main(int argc, char *argv[])
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
void Register(OptionsItf *opts)
Definition: plda.h:300
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.
This class takes unlabeled iVectors from the domain of interest and uses their mean and variance to a...
Definition: plda.h:319
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void AddStats(double weight, const Vector< double > &ivector)
Definition: plda.cc:595
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void UpdatePlda(const PldaUnsupervisedAdaptorConfig &config, Plda *plda) const
Definition: plda.cc:613
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257