29 mat->
Row(
i).ApplySoftMax();
35 int main(
int argc,
char *argv[]) {
37 using namespace kaldi;
40 "Copy matrices, or archives of matrices (e.g. features or transforms)\n" 41 "Also see copy-feats which has other format options\n" 43 "Usage: copy-matrix [options] <matrix-in-rspecifier> <matrix-out-wspecifier>\n" 44 " or: copy-matrix [options] <matrix-in-rxfilename> <matrix-out-wxfilename>\n" 45 " e.g.: copy-matrix --binary=false 1.mat -\n" 46 " copy-matrix ark:2.trans ark,t:-\n" 47 "See also: copy-feats, matrix-sum\n";
50 bool apply_log =
false;
51 bool apply_exp =
false;
52 bool apply_softmax_per_row =
false;
59 "Write in binary mode (only relevant if output is a wxfilename)");
61 "This option can be used to scale the matrices being copied.");
63 "This option can be used to apply log on the matrices. " 64 "Must be avoided if matrix has negative quantities.");
66 "This option can be used to apply exp on the matrices");
67 po.
Register(
"apply-power", &apply_power,
68 "This option can be used to apply a power on the matrices");
69 po.
Register(
"apply-softmax-per-row", &apply_softmax_per_row,
70 "This option can be used to apply softmax per row of the matrices");
79 if ( (apply_log && apply_exp) || (apply_softmax_per_row && apply_exp) ||
80 (apply_softmax_per_row && apply_log) )
81 KALDI_ERR <<
"Only one of apply-log, apply-exp and " 82 <<
"apply-softmax-per-row can be given";
84 std::string matrix_in_fn = po.
GetArg(1),
85 matrix_out_fn = po.
GetArg(2);
89 bool in_is_rspecifier =
96 if (in_is_rspecifier != out_is_wspecifier)
97 KALDI_ERR <<
"Cannot mix archives with regular files (copying matrices)";
99 if (!in_is_rspecifier) {
102 if (scale != 1.0) mat.
Scale(scale);
109 if (apply_power != 1.0) mat.
ApplyPow(apply_power);
110 Output ko(matrix_out_fn, binary);
112 KALDI_LOG <<
"Copied matrix to " << matrix_out_fn;
118 for (; !reader.
Done(); reader.
Next(), num_done++) {
119 if (scale != 1.0 || apply_log || apply_exp ||
120 apply_power != 1.0 || apply_softmax_per_row) {
122 if (scale != 1.0) mat.
Scale(scale);
124 mat.ApplyFloor(1.0e-20);
127 if (apply_exp) mat.ApplyExp();
129 if (apply_power != 1.0) mat.ApplyPow(apply_power);
135 KALDI_LOG <<
"Copied " << num_done <<
" matrices.";
136 return (num_done != 0 ? 0 : 1);
138 }
catch(
const std::exception &e) {
139 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Write(std::ostream &out, bool binary) const
write to stream.
int main(int argc, char *argv[])
Base class which provides matrix operations not involving resizing or allocation. ...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
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...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void Scale(Real alpha)
Multiply each element with a scalar value.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void ApplySoftMaxPerRow(MatrixBase< BaseFloat > *mat)
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.
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void ApplyFloor(Real floor_val)
void ApplyPow(Real power)