ivector-extractor-est.cc
Go to the documentation of this file.
1 // ivectorbin/ivector-extractor-est.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 #include "util/common-utils.h"
22 #include "util/kaldi-thread.h"
23 
24 int main(int argc, char *argv[]) {
25  try {
26  typedef kaldi::int32 int32;
27  using namespace kaldi;
28 
29  const char *usage =
30  "Do model re-estimation of iVector extractor (this is\n"
31  "the update phase of a single pass of E-M)\n"
32  "Usage: ivector-extractor-est [options] <model-in> <stats-in> <model-out>\n";
33 
34  bool binary = true;
36 
37  kaldi::ParseOptions po(usage);
38  po.Register("binary", &binary, "Write output in binary mode");
39  po.Register("num-threads", &g_num_threads,
40  "Number of threads used in update");
41 
42  update_opts.Register(&po);
43 
44  po.Read(argc, argv);
45 
46  if (po.NumArgs() != 3) {
47  po.PrintUsage();
48  exit(1);
49  }
50 
51  std::string model_rxfilename = po.GetArg(1),
52  stats_rxfilename = po.GetArg(2),
53  model_wxfilename = po.GetArg(3);
54 
55  KALDI_LOG << "Reading model";
56  IvectorExtractor extractor;
57  ReadKaldiObject(model_rxfilename, &extractor);
58 
59  KALDI_LOG << "Reading statistics";
61  ReadKaldiObject(stats_rxfilename, &stats);
62 
63  stats.Update(update_opts, &extractor);
64  WriteKaldiObject(extractor, model_wxfilename, binary);
65  stats.IvectorVarianceDiagnostic(extractor);
66 
67  KALDI_LOG << "Updated model and wrote it to "
68  << model_wxfilename;
69 
70  return 0;
71  } catch(const std::exception &e) {
72  std::cerr << e.what() << '\n';
73  return -1;
74  }
75 }
76 
77 
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].
int32 g_num_threads
Definition: kaldi-thread.cc:25
IvectorExtractorStats is a class used to update the parameters of the ivector extractor.
kaldi::int32 int32
int main(int argc, char *argv[])
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
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
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.
double Update(const IvectorExtractorEstimationOptions &opts, IvectorExtractor *extractor) const
Returns the objf improvement per frame.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
Options for training the IvectorExtractor, e.g. variance flooring.
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153
void IvectorVarianceDiagnostic(const IvectorExtractor &extractor)
Prints the proportion of the variance explained by the Ivector model versus the Gaussians.