29 using namespace kaldi;
32 "Copy vectors, or archives of vectors (e.g. transition-accs; speaker vectors)\n" 34 "Usage: copy-vector [options] (<vector-in-rspecifier>|<vector-in-rxfilename>) (<vector-out-wspecifier>|<vector-out-wxfilename>)\n" 35 " e.g.: copy-vector --binary=false 1.mat -\n" 36 " copy-vector ark:2.trans ark,t:-\n" 37 "see also: dot-weights, append-vector-to-feats\n";
40 int32 change_dim = -1;
44 po.Register(
"binary", &binary,
"Write in binary mode (only " 45 "relevant if output is a wxfilename)");
46 po.Register(
"change_dim", &change_dim,
47 "Use this option to truncate or zero-pad the vectors.");
48 po.Register(
"scale", &scale,
49 "This option can be used to scale the vectors being copied.");
53 if (po.NumArgs() != 2) {
59 std::string vector_in_fn = po.GetArg(1),
60 vector_out_fn = po.GetArg(2);
64 bool in_is_rspecifier =
71 if (in_is_rspecifier != out_is_wspecifier)
72 KALDI_ERR <<
"Cannot mix archives with regular files (copying vectors)";
74 if (!in_is_rspecifier) {
77 Output ko(vector_out_fn, binary);
79 vec.
Write(ko.Stream(), binary);
80 KALDI_LOG <<
"Copied vector to " << vector_out_fn;
86 if (change_dim < 0 && scale == 1.0) {
87 for (; !reader.Done(); reader.Next(), num_done++) {
88 writer.Write(reader.Key(), reader.Value());
90 KALDI_LOG <<
"Copied " << num_done <<
" vectors.";
92 for (; !reader.Done(); reader.Next(), num_done++) {
95 if (scale != 1.0) vec.
Scale(scale);
96 writer.Write(reader.Key(), reader.Value());
98 KALDI_LOG <<
"Copied " << num_done <<
" vectors, setting dim to " 99 << change_dim <<
" scaled by " << scale;
101 return (num_done != 0 ? 0 : 1);
103 }
catch(
const std::exception &e) {
104 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
Writes to C++ stream (option to write in binary).
A templated class for writing objects to an archive or script file; see The Table concept...
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
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...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Scale(Real alpha)
Multiplies all elements by this constant.
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
A class representing a vector.