29 using namespace kaldi;
32 "Compose (affine or linear) feature transforms\n" 33 "Usage: compose-transforms [options] (<transform-A-rspecifier>|<transform-A-rxfilename>) " 34 "(<transform-B-rspecifier>|<transform-B-rxfilename>) (<transform-out-wspecifier>|<transform-out-wxfilename>)\n" 35 " Note: it does matrix multiplication (A B) so B is the transform that gets applied\n" 36 " to the features first. If b-is-affine = true, then assume last column of b corresponds to offset\n" 37 " e.g.: compose-transforms 1.mat 2.mat 3.mat\n" 38 " compose-transforms 1.mat ark:2.trans ark:3.trans\n" 39 " compose-transforms ark:1.trans ark:2.trans ark:3.trans\n" 40 " See also: transform-feats, transform-vec, extend-transform-dim, est-lda, est-pca\n";
42 bool b_is_affine =
false;
44 std::string utt2spk_rspecifier;
47 po.Register(
"utt2spk", &utt2spk_rspecifier,
"rspecifier for utterance to speaker map (if mixing utterance and speaker ids)");
49 po.Register(
"b-is-affine", &b_is_affine,
"If true, treat last column of transform b as an offset term (only relevant if a is affine)");
50 po.Register(
"binary", &binary,
"Write in binary mode (only relevant if output is a wxfilename)");
54 if (po.NumArgs() != 3) {
60 std::string transform_a_fn = po.GetArg(1);
61 std::string transform_b_fn = po.GetArg(2);
62 std::string transform_c_fn = po.GetArg(3);
66 bool a_is_rspecifier =
78 if (utt2spk_rspecifier !=
"") {
79 if (!(a_is_rspecifier && b_is_rspecifier))
80 KALDI_ERR <<
"Error: utt2spk option provided compose transforms but " 81 "at least one of the inputs is a global transform.";
82 if (!utt2spk_reader.
Open(utt2spk_rspecifier))
83 KALDI_ERR <<
"Error upening utt2spk map from " 84 << utt2spk_rspecifier;
88 if ( (a_is_rspecifier || b_is_rspecifier) != c_is_wspecifier)
89 KALDI_ERR <<
"Formats of the input and output rspecifiers/rxfilenames do " 90 "not match (if either a or b is an rspecifier, then the output must " 94 if (a_is_rspecifier || b_is_rspecifier) {
96 if (a_is_rspecifier) {
98 if (b_is_rspecifier) {
100 for (;!a_reader.Done(); a_reader.Next()) {
101 if (utt2spk_rspecifier !=
"") {
102 std::string utt = a_reader.Key();
103 if (!utt2spk_reader.
HasKey(utt)) {
104 KALDI_WARN <<
"No speaker provided for utterance " << utt
105 <<
" (perhaps you wrongly provided utt2spk option to " 106 " compose-transforms?)";
109 std::string spk = utt2spk_reader.
Value(utt);
110 if (!b_reader.HasKey(spk)) {
111 KALDI_WARN <<
"Second table does not have key " << spk;
118 c_writer.
Write(utt, c);
120 if (!b_reader.HasKey(a_reader.Key())) {
121 KALDI_WARN <<
"Second table does not have key " << a_reader.Key();
127 c_writer.
Write(a_reader.Key(), c);
134 for (;!a_reader.Done(); a_reader.Next()) {
139 c_writer.
Write(a_reader.Key(), c);
146 for (; !b_reader.Done(); b_reader.Next()) {
151 c_writer.
Write(b_reader.Key(), c);
162 KALDI_WARN <<
"It looks like you are trying to compose two affine transforms" 163 <<
", but you omitted the --b-is-affine option.";
169 }
catch(
const std::exception &e) {
170 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.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
bool Open(const std::string &rspecifier)
A templated class for writing objects to an archive or script file; see The Table concept...
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
bool HasKey(const std::string &key)
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
bool ComposeTransforms(const Matrix< BaseFloat > &a, const Matrix< BaseFloat > &b, bool b_is_affine, Matrix< BaseFloat > *c)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)