fmpe-apply-transform.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "transform/fmpe.h"
Include dependency graph for fmpe-apply-transform.cc:

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 24 of file fmpe-apply-transform.cc.

References Fmpe::ComputeFeatures(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), RandomAccessTableReader< Holder >::HasKey(), KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), kaldi::kNoTrans, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), RandomAccessTableReader< Holder >::Value(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

24  {
25  using namespace kaldi;
26  using kaldi::int32;
27  try {
28  const char *usage =
29  "Apply fMPE transform to features\n"
30  "Usage: fmpe-apply-transform [options...] <fmpe-object> "
31  "<feat-rspecifier> <gselect-rspecifier> <feat-wspecifier>\n";
32 
33  ParseOptions po(usage);
34  bool add_to_features = true;
35  po.Register("add-to-features", &add_to_features, "If true, add original "
36  "features to fMPE offsets (false useful for diagnostics)");
37  // no non-default options.
38  po.Read(argc, argv);
39 
40  if (po.NumArgs() != 4) {
41  po.PrintUsage();
42  exit(1);
43  }
44 
45  std::string fmpe_rxfilename = po.GetArg(1),
46  feat_rspecifier = po.GetArg(2),
47  gselect_rspecifier = po.GetArg(3),
48  feat_wspecifier = po.GetArg(4);
49 
50  Fmpe fmpe;
51  ReadKaldiObject(fmpe_rxfilename, &fmpe);
52 
53  SequentialBaseFloatMatrixReader feat_reader(feat_rspecifier);
54  RandomAccessInt32VectorVectorReader gselect_reader(gselect_rspecifier);
55  BaseFloatMatrixWriter feat_writer(feat_wspecifier);
56 
57  int32 num_done = 0, num_err = 0;
58 
59  for (; !feat_reader.Done(); feat_reader.Next()) {
60  std::string key = feat_reader.Key();
61  const Matrix<BaseFloat> feat_in(feat_reader.Value());
62  if (!gselect_reader.HasKey(key)) {
63  KALDI_WARN << "No gselect information for key " << key;
64  num_err++;
65  continue;
66  }
67  const std::vector<std::vector<int32> > &gselect =
68  gselect_reader.Value(key);
69  if (static_cast<int32>(gselect.size()) != feat_in.NumRows()) {
70  KALDI_WARN << "gselect information has wrong size";
71  num_err++;
72  continue;
73  }
74  Matrix<BaseFloat> feat_out(feat_in.NumRows(), feat_in.NumCols());
75  fmpe.ComputeFeatures(feat_in, gselect, &feat_out);
76  if (add_to_features) // feat_out += feat_in.
77  feat_out.AddMat(1.0, feat_in, kNoTrans);
78 
79  feat_writer.Write(key, feat_out);
80  num_done++;
81  }
82  KALDI_LOG << " Done " << num_done << " utterances, " << num_err
83  << " had errors.";
84  return (num_done != 0 ? 0 : 1);
85  } catch(const std::exception &e) {
86  std::cerr << e.what();
87  return -1;
88  }
89 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void ComputeFeatures(const MatrixBase< BaseFloat > &feat_in, const std::vector< std::vector< int32 > > &gselect, Matrix< BaseFloat > *feat_out) const
Definition: fmpe.cc:370
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
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:150
#define KALDI_LOG
Definition: kaldi-error.h:153