38 std::string vector_in_fn1 = po.
GetArg(1),
39 vector_out_fn = po.
GetArg(num_args);
46 std::vector<RandomAccessBaseFloatVectorReader*> vector_readers(num_args-2,
47 static_cast<RandomAccessBaseFloatVectorReader*>(NULL));
48 std::vector<std::string> vector_in_fns(num_args-2);
49 for (
int32 i = 2;
i < num_args; ++
i) {
54 int32 n_utts = 0, n_total_vectors = 0,
55 n_success = 0, n_missing = 0, n_other_errors = 0;
57 for (; !vector_reader1.
Done(); vector_reader1.
Next()) {
58 std::string key = vector_reader1.
Key();
66 for (
int32 i = 0;
i < num_args-2; ++
i) {
67 if (vector_readers[
i]->HasKey(key)) {
70 if (vector2.
Dim() == vector_out.
Dim()) {
71 vector_out.
AddVec(1.0, vector2);
73 KALDI_WARN <<
"Dimension mismatch for utterance " << key
74 <<
" : " << vector2.
Dim() <<
" for " 75 <<
"system " << (
i + 2) <<
", rspecifier: " 76 << vector_in_fns[
i] <<
" vs " << vector_out.
Dim()
77 <<
" primary vector, rspecifier:" << vector_in_fn1;
81 KALDI_WARN <<
"No vector found for utterance " << key <<
" for " 82 <<
"system " << (
i + 2) <<
", rspecifier: " 88 vector_writer.
Write(key, vector_out);
92 KALDI_LOG <<
"Processed " << n_utts <<
" utterances: with a total of " 93 << n_total_vectors <<
" vectors across " << (num_args-1)
94 <<
" different systems";
95 KALDI_LOG <<
"Produced output for " << n_success <<
" utterances; " 96 << n_missing <<
" total missing vectors";
100 return (n_success != 0 && n_missing < (n_success - n_missing)) ? 0 : 1;
105 bool average =
false) {
108 "vector-sum: first argument must be an rspecifier");
118 int32 num_done = 0, num_err = 0;
120 for (; !vec_reader.Done(); vec_reader.Next()) {
122 if (vec.
Dim() == 0) {
123 KALDI_WARN <<
"Zero vector input for key " << vec_reader.Key();
126 if (sum.Dim() == 0) sum.Resize(vec.
Dim());
127 if (sum.Dim() != vec.
Dim()) {
128 KALDI_WARN <<
"Dimension mismatch for key " << vec_reader.Key()
129 <<
": " << vec.
Dim() <<
" vs. " << sum.Dim();
132 sum.AddVec(1.0, vec);
138 if (num_done > 0 && average) sum.Scale(1.0 / num_done);
143 KALDI_LOG <<
"Summed " << num_done <<
" vectors, " 144 << num_err <<
" with errors; wrote sum to " 146 return (num_done > 0 && num_err < num_done) ? 0 : 1;
156 KALDI_ERR <<
"Wrong usage (type 3): if first and last arguments are not " 157 <<
"tables, the intermediate arguments must not be tables.";
162 KALDI_ERR <<
"Wrong usage (type 3): if first and last arguments are not " 163 <<
"tables, the intermediate arguments must not be tables.";
170 if (sum.
Dim() < this_vec.
Dim())
172 sum.
AddVec(1.0, this_vec);
184 int main(
int argc,
char *argv[]) {
186 using namespace kaldi;
189 "Add vectors (e.g. weights, transition-accs; speaker vectors)\n" 190 "If you need to scale the inputs, use vector-scale on the inputs\n" 193 " vector-sum [options] <vector-in-rspecifier1> [<vector-in-rspecifier2>" 194 " <vector-in-rspecifier3> ...] <vector-out-wspecifier>\n" 195 " e.g.: vector-sum ark:1.weights ark:2.weights ark:combine.weights\n" 196 "Type two usage (sums a single table input to produce a single output):\n" 197 " vector-sum [options] <vector-in-rspecifier> <vector-out-wxfilename>\n" 198 " e.g.: vector-sum --binary=false vecs.ark sum.vec\n" 199 "Type three usage (sums single-file inputs to produce a single output):\n" 200 " vector-sum [options] <vector-in-rxfilename1> <vector-in-rxfilename2> ..." 201 " <vector-out-wxfilename>\n" 202 " e.g.: vector-sum --binary=false 1.vec 2.vec 3.vec sum.vec\n" 203 "See also: copy-vector, dot-weights\n";
205 bool binary, average =
false;
209 po.
Register(
"binary", &binary,
"If true, write output as binary (only " 210 "relevant for usage types two or three");
211 po.
Register(
"average", &average,
"Do average instead of sum");
221 }
else if (po.
NumArgs() == 2 &&
227 }
else if (po.
NumArgs() >= 2 &&
238 }
catch(
const std::exception &e) {
239 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
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 Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
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)
int32 TypeTwoUsage(const ParseOptions &po, bool binary)
int32 TypeOneUsage(const ParseOptions &po, BaseFloat scale1, BaseFloat scale2)
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...
int main(int argc, char *argv[])
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.
MatrixIndexT Dim() const
Returns the dimension of the vector.
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).
A class representing a vector.
#define KALDI_ASSERT(cond)
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
RandomAccessTableReader< KaldiObjectHolder< Vector< BaseFloat > > > RandomAccessBaseFloatVectorReader
int32 TypeThreeUsage(const ParseOptions &po, bool binary, bool average)