sgmm2-copy.cc
Go to the documentation of this file.
1 // sgmm2bin/sgmm2-copy.cc
2 
3 // Copyright 2009-2012 Microsoft Corporation
4 // Johns Hopkins University (author: Daniel Povey).
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 
22 #include "base/kaldi-common.h"
23 #include "util/common-utils.h"
24 
25 #include "sgmm2/am-sgmm2.h"
26 #include "hmm/transition-model.h"
27 
28 int main(int argc, char *argv[]) {
29  try {
30  using namespace kaldi;
31  typedef kaldi::int32 int32;
32  const char *usage =
33  "Copy SGMM (possibly changing binary/text format)\n"
34  "Usage: sgmm2-copy [options] <model-in> <model-out>\n"
35  "e.g.: sgmm2-copy --binary=false 1.mdl 1_text.mdl\n";
36 
37  bool binary_write = true;
38 
39  ParseOptions po(usage);
40  po.Register("binary", &binary_write, "Write output in binary mode");
41 
42  po.Read(argc, argv);
43  if (po.NumArgs() != 2) {
44  po.PrintUsage();
45  exit(1);
46  }
47  std::string model_in_filename = po.GetArg(1),
48  model_out_filename = po.GetArg(2);
49 
50  AmSgmm2 am_sgmm;
51  TransitionModel trans_model;
52  {
53  bool binary;
54  Input ki(model_in_filename, &binary);
55  trans_model.Read(ki.Stream(), binary);
56  am_sgmm.Read(ki.Stream(), binary);
57  }
58 
59  {
60  Output ko(model_out_filename, binary_write);
61  trans_model.Write(ko.Stream(), binary_write);
62  am_sgmm.Write(ko.Stream(), binary_write, kSgmmWriteAll);
63  }
64 
65 
66  KALDI_LOG << "Written model to " << model_out_filename;
67  return 0;
68  } catch(const std::exception &e) {
69  std::cerr << e.what();
70  return -1;
71  }
72 }
73 
74 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Write(std::ostream &os, bool binary, SgmmWriteFlagsType write_params) const
Definition: am-sgmm2.cc:203
Class for definition of the subspace Gmm acoustic model.
Definition: am-sgmm2.h:231
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Read(std::istream &is, bool binary)
Definition: am-sgmm2.cc:89
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
#define KALDI_LOG
Definition: kaldi-error.h:153
int main(int argc, char *argv[])
Definition: sgmm2-copy.cc:28