33 if (in.
NumRows() != post.size()) {
35 <<
" features: " << in.
NumRows()
36 <<
" posteriors: " << post.size();
50 int main(
int argc,
char *argv[]) {
52 using namespace kaldi;
56 "Append posteriors to features\n" 58 "Usage: append-post-to-feats [options] <in-rspecifier1> <in-rspecifier2> <out-wspecifier>\n" 59 " or: append-post-to-feats [options] <in-rxfilename1> <in-rxfilename2> <out-wxfilename>\n" 60 "e.g.: append-post-to-feats --post-dim=50 ark:input.ark scp:post.scp ark:output.ark\n" 61 "See also: paste-feats, concat-feats, append-vector-to-feats\n";
66 po.
Register(
"binary", &binary,
"If true, output files in binary " 67 "(only relevant for single-file operation, i.e. no tables)");
70 po.
Register(
"post-dim", &post_dim,
"Dimensionality of the posteriors.");
80 KALDI_ERR <<
"You have to set the dimensionality of posteriors " 81 "with '--post-dim=D'";
88 string feat_rspecifier = po.
GetArg(1);
91 string post_rspecifier = po.
GetArg(2);
94 string wspecifier = po.
GetArg(3);
97 int32 num_done = 0, num_err = 0;
99 for (; !feat_reader.
Done(); feat_reader.
Next()) {
100 string utt = feat_reader.
Key();
101 KALDI_VLOG(2) <<
"Processing utterance " << utt;
105 if (!post_reader.
HasKey(utt)) {
106 KALDI_WARN <<
"Could not read posteriors for utterance " << utt;
114 feat_writer.
Write(utt, output);
117 KALDI_LOG <<
"Done " << num_done <<
" utts, errors on " 120 return (num_done == 0 ? -1 : 0);
134 std::string output_wxfilename = po.
GetArg(3);
136 KALDI_LOG <<
"Wrote appended features to " << output_wxfilename;
139 }
catch(
const std::exception &e) {
140 std::cerr << e.what();
void PosteriorToMatrix(const Posterior &post, const int32 post_dim, Matrix< Real > *mat)
This converts a Posterior to a Matrix.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void AppendPostToFeats(const Matrix< BaseFloat > &in, const Posterior &post, const int32 post_dim, Matrix< BaseFloat > *out)
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
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 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)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
SubMatrix< Real > ColRange(const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
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.
int main(int argc, char *argv[])
bool HasKey(const std::string &key)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
void ReadPosterior(std::istream &is, bool binary, Posterior *post)
stand-alone function for reading a Posterior.