27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
32 "Compute SGMM model projection that only models a part of a pre-LDA space.\n" 33 "Used in predictive SGMMs. Takes as input an LDA+MLLT transform,\n" 34 "and outputs a transform from the pre-LDA+MLLT space to the space that\n" 36 "Usage: sgmm2-project [options] <model-in> <lda-mllt-mat-in> <model-out> <new-projection-out>\n" 37 "e.g.: sgmm2-project --start-dim=0 --end-dim=52 final.mdl final.inv_full_mat final_proj1.mdl proj1.mat\n";
39 std::string write_flags_str =
"gsnu";
41 bool binary_write =
false;
46 po.
Register(
"binary", &binary_write,
"Write output in binary mode");
47 po.
Register(
"start-dim", &start_dim,
"Starting dimension to keep in " 48 "pre-LDA-MLLT space.");
49 po.
Register(
"end-dim", &end_dim,
"Ending dimension to keep in " 50 "pre-LDA-MLLT space (equals last retained dimension plus one)");
57 std::string model_rxfilename = po.
GetArg(1),
58 lda_mllt_rxfilename = po.
GetArg(2),
59 model_wxfilename = po.
GetArg(3),
60 proj_wxfilename = po.
GetArg(4);
69 Input ki(model_rxfilename, &binary);
83 inv_lda_mllt_mat.Invert();
100 Output ko(model_wxfilename, binary_write);
102 am_sgmm.
Write(ko.
Stream(), binary_write, write_flags);
104 KALDI_LOG <<
"Wrote model to " << model_wxfilename;
107 KALDI_LOG <<
"Wrote projection matrix to " << proj_wxfilename;
110 }
catch(
const std::exception &e) {
111 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
uint16 SgmmWriteFlagsType
Bitwise OR of the above flags.
void Write(std::ostream &os, bool binary, SgmmWriteFlagsType write_params) const
Class for definition of the subspace Gmm acoustic model.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Read(std::istream &is, bool binary)
void ComputeProjection(const AmSgmm2 &sgmm, const Matrix< BaseFloat > &inv_lda_mllt, int32 begin_dim, int32 end_dim, Matrix< BaseFloat > *projection)
void ApplyProjection(const Matrix< BaseFloat > &total_projection, AmSgmm2 *sgmm)
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
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 main(int argc, char *argv[])
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void Write(std::ostream &os, bool binary) const
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void ComputeDerivedVars()
Computes (and initializes if necessary) derived vars...
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
SgmmUpdateFlagsType StringToSgmmWriteFlags(std::string str)