gmm-copy.cc
Go to the documentation of this file.
1 // gmmbin/gmm-copy.cc
2 
3 // Copyright 2009-2011 Microsoft Corporation
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 "base/kaldi-common.h"
21 #include "util/common-utils.h"
22 #include "gmm/am-diag-gmm.h"
23 #include "hmm/transition-model.h"
24 
25 int main(int argc, char *argv[]) {
26  try {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29 
30  const char *usage =
31  "Copy GMM based model (and possibly change binary/text format)\n"
32  "Usage: gmm-copy [options] <model-in> <model-out>\n"
33  "e.g.:\n"
34  " gmm-copy --binary=false 1.mdl 1_txt.mdl\n";
35 
36 
37  bool binary_write = true,
38  copy_am = true,
39  copy_tm = true;
40 
41  ParseOptions po(usage);
42  po.Register("binary", &binary_write, "Write output in binary mode");
43  po.Register("copy-am", &copy_am, "Copy the acoustic model (AmDiagGmm object)");
44  po.Register("copy-tm", &copy_tm, "Copy the transition model");
45 
46  po.Read(argc, argv);
47 
48  if (po.NumArgs() != 2) {
49  po.PrintUsage();
50  exit(1);
51  }
52 
53  std::string model_in_filename = po.GetArg(1),
54  model_out_filename = po.GetArg(2);
55 
56  AmDiagGmm am_gmm;
57  TransitionModel trans_model;
58  {
59  bool binary_read;
60  Input ki(model_in_filename, &binary_read);
61  if (copy_tm)
62  trans_model.Read(ki.Stream(), binary_read);
63  if (copy_am)
64  am_gmm.Read(ki.Stream(), binary_read);
65  }
66 
67  {
68  Output ko(model_out_filename, binary_write);
69  if (copy_tm)
70  trans_model.Write(ko.Stream(), binary_write);
71  if (copy_am)
72  am_gmm.Write(ko.Stream(), binary_write);
73  }
74 
75  KALDI_LOG << "Written model to " << model_out_filename;
76  } catch(const std::exception &e) {
77  std::cerr << e.what() << '\n';
78  return -1;
79  }
80 }
81 
82 
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: gmm-copy.cc:25
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)
std::istream & Stream()
Definition: kaldi-io.cc:826
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
std::ostream & Stream()
Definition: kaldi-io.cc:701
void Read(std::istream &is, bool binary)
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 Write(std::ostream &os, bool binary) const
void Write(std::ostream &out_stream, bool binary) const
Definition: am-diag-gmm.cc:163
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &in_stream, bool binary)
Definition: am-diag-gmm.cc:147