28 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
33 "Normalize length of iVectors to equal sqrt(feature-dimension)\n" 35 "Usage: ivector-normalize-length [options] <ivector-rspecifier> " 36 "<ivector-wspecifier>\n" 38 " ivector-normalize-length ark:ivectors.ark ark:normalized_ivectors.ark\n";
41 bool normalize =
true;
44 "Set this to false to disable normalization");
48 "If 'true', the normalized iVector is scaled-up by 'sqrt(dim)'");
57 std::string ivector_rspecifier = po.
GetArg(1),
58 ivector_wspecifier = po.
GetArg(2);
63 double tot_ratio = 0.0, tot_ratio2 = 0.0;
69 for (; !ivector_reader.
Done(); ivector_reader.
Next()) {
70 std::string key = ivector_reader.
Key();
76 if (!scaleup) ratio = norm;
78 KALDI_VLOG(2) <<
"Ratio for key " << key <<
" is " << ratio;
82 if (normalize) ivector.
Scale(1.0 / ratio);
84 ivector_writer.
Write(key, ivector);
86 tot_ratio2 += ratio * ratio;
90 KALDI_LOG <<
"Processed " << num_done <<
" iVectors.";
92 BaseFloat avg_ratio = tot_ratio / num_done,
93 ratio_stddev = sqrt(tot_ratio2 / num_done - avg_ratio * avg_ratio);
94 KALDI_LOG <<
"Average ratio of iVector to expected length was " 95 << avg_ratio <<
", standard deviation was " << ratio_stddev;
97 return (num_done != 0 ? 0 : 1);
98 }
catch(
const std::exception &e) {
99 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
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...
Real Norm(Real p) const
Compute the p-th norm of the vector.
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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 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.
void Scale(Real alpha)
Multiplies all elements by this constant.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
int main(int argc, char *argv[])