All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dot-weights.cc File Reference
Include dependency graph for dot-weights.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 25 of file dot-weights.cc.

References VectorBase< Real >::Dim(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), RandomAccessTableReader< Holder >::HasKey(), KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), RandomAccessTableReader< Holder >::Value(), SequentialTableReader< Holder >::Value(), kaldi::VecVec(), and TableWriter< Holder >::Write().

25  {
26  try {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29 
30  const char *usage =
31  "Takes two archives of vectors (typically representing per-frame weights)\n"
32  "and for each utterance, outputs the dot product.\n"
33  "Useful for evaluating the accuracy of silence classifiers.\n"
34  "Usage: dot-weights <weights-rspecifier1> <weights-rspecifier2> <float-wspecifier>\n";
35 
36  ParseOptions po(usage);
37  po.Read(argc, argv);
38 
39  if (po.NumArgs() != 3) {
40  po.PrintUsage();
41  exit(1);
42  }
43 
44  std::string weights1_rspecifier = po.GetArg(1),
45  weights2_rspecifier = po.GetArg(2),
46  float_wspecifier = po.GetArg(3);
47 
48  kaldi::SequentialBaseFloatVectorReader weights1_reader(weights1_rspecifier);
49  kaldi::RandomAccessBaseFloatVectorReader weights2_reader(weights2_rspecifier);
50  kaldi::BaseFloatWriter float_writer(float_wspecifier);
51 
52  int32 num_done = 0, num_err = 0;
53 
54  for (; !weights1_reader.Done(); weights1_reader.Next()) {
55  std::string key = weights1_reader.Key();
56  const Vector<BaseFloat> &weights1 = weights1_reader.Value();
57  if (!weights2_reader.HasKey(key)) {
58  KALDI_WARN << "No weights for utterance " << key << " in second table.";
59  num_err++;
60  } else {
61  const Vector<BaseFloat> &weights2 = weights2_reader.Value(key);
62  // Next line will crash if different sizes. This is the
63  // behavior we want [for now].
64  if (weights1.Dim() != weights2.Dim()) {
65  KALDI_WARN << "Dimension mismatch for utterance " << key
66  << " : " << weights1.Dim() << " vs. " << weights2.Dim();
67  num_err++;
68  continue;
69  }
70  BaseFloat dot = VecVec(weights1, weights2);
71  float_writer.Write(key, dot);
72  num_done++;
73  }
74  }
75  KALDI_LOG << "Done computing dot products of " << num_done
76  << " weights; errors on " << num_err;
77  return (num_done != 0 ? 0 : 1);
78  } catch(const std::exception &e) {
79  std::cerr << e.what();
80  return -1;
81  }
82 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_WARN
Definition: kaldi-error.h:130
#define KALDI_LOG
Definition: kaldi-error.h:133
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:36
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62