ivector-extractor-init.cc
Go to the documentation of this file.
1 // ivectorbin/ivector-extractor-init.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 "gmm/full-gmm.h"
25 
26 
27 int main(int argc, char *argv[]) {
28  try {
29  using namespace kaldi;
30  using kaldi::int32;
31 
32  const char *usage =
33  "Initialize ivector-extractor\n"
34  "Usage: ivector-extractor-init [options] <fgmm-in> <ivector-extractor-out>\n"
35  "e.g.:\n"
36  " ivector-extractor-init 4.fgmm 0.ie\n";
37 
38  bool binary = true;
39  IvectorExtractorOptions ivector_opts;
40  ParseOptions po(usage);
41  po.Register("binary", &binary, "Write output in binary mode");
42  ivector_opts.Register(&po);
43 
44  po.Read(argc, argv);
45 
46  if (po.NumArgs() != 2) {
47  po.PrintUsage();
48  exit(1);
49  }
50 
51 
52  std::string fgmm_rxfilename = po.GetArg(1),
53  ivector_extractor_wxfilename = po.GetArg(2);
54 
55  FullGmm fgmm;
56  ReadKaldiObject(fgmm_rxfilename, &fgmm);
57 
58  IvectorExtractor extractor(ivector_opts, fgmm);
59 
60  WriteKaldiObject(extractor, ivector_extractor_wxfilename, binary);
61 
62  KALDI_LOG << "Initialized iVector extractor with iVector dimension "
63  << extractor.IvectorDim() << " and wrote it to "
64  << ivector_extractor_wxfilename;
65  return 0;
66  } catch(const std::exception &e) {
67  std::cerr << e.what();
68  return -1;
69  }
70 }
71 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int main(int argc, char *argv[])
Definition for Gaussian Mixture Model with full covariances.
Definition: full-gmm.h:40
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
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void Register(OptionsItf *opts)
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153