40 bool need_backprop =
false, store_stats =
false;
54 void WriteStats(
const std::string &stats_wxfilename,
bool binary) {
59 KALDI_LOG <<
"Accumulated stats, soft frame count = " 68 const NnetIo *output_supervision = NULL;
69 for (
size_t i = 0;
i < eg.
io.size();
i++)
70 if (eg.
io[
i].name ==
"output")
71 output_supervision = &(eg.
io[
i]);
72 KALDI_ASSERT(output_supervision != NULL &&
"no output in eg named 'output'");
81 for (
int32 r = 0; r < num_rows; r++) {
91 const std::pair<MatrixIndexT, BaseFloat> *post_data = post.
Data(),
93 for (; post_data != post_end; ++post_data) {
97 if (pruned_weight != 0.0)
104 for (
int32 r = 0; r < num_rows; r++) {
115 for (
int32 pdf = 0; pdf < num_pdfs; pdf++) {
118 if (pruned_weight != 0.0)
135 int main(
int argc,
char *argv[]) {
137 using namespace kaldi;
140 typedef kaldi::int64 int64;
143 "Accumulate statistics in the same format as acc-lda (i.e. stats for\n" 144 "estimation of LDA and similar types of transform), starting from nnet\n" 145 "training examples. This program puts the features through the network,\n" 146 "and the network output will be the features; the supervision in the\n" 147 "training examples is used for the class labels. Used in obtaining\n" 148 "feature transforms that help nnet training work better.\n" 150 "Usage: nnet3-acc-lda-stats [options] <raw-nnet-in> <training-examples-in> <lda-stats-out>\n" 152 "nnet3-acc-lda-stats 0.raw ark:1.egs 1.acc\n" 153 "See also: nnet-get-feature-transform\n";
155 bool binary_write =
true;
159 po.
Register(
"binary", &binary_write,
"Write output in binary mode");
160 po.
Register(
"rand-prune", &rand_prune,
161 "Randomized pruning threshold for posteriors");
170 std::string nnet_rxfilename = po.
GetArg(1),
171 examples_rspecifier = po.
GetArg(2),
172 lda_accs_wxfilename = po.
GetArg(3);
182 for (; !example_reader.
Done(); example_reader.
Next(), num_egs++)
185 KALDI_LOG <<
"Processed " << num_egs <<
" examples.";
187 accumulator.
WriteStats(lda_accs_wxfilename, binary_write);
190 }
catch(
const std::exception &e) {
191 std::cerr << e.what() <<
'\n';
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
void Accumulate(const VectorBase< BaseFloat > &data, int32 class_id, BaseFloat weight=1.0)
Accumulates data.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int main(int argc, char *argv[])
Class for computing linear discriminant analysis (LDA) transform.
void GetMatrix(Matrix< BaseFloat > *mat) const
Outputs the contents as a matrix.
int32 Dim() const
Returns the dimensionality of the feature vectors.
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int32 GetVerboseLevel()
Get verbosity level, usually set via command line '–verbose=' switch.
Float RandPrune(Float post, BaseFloat prune_thresh, struct RandomState *state=NULL)
This class enables you to do the compilation and optimization in one call, and also ensures that if t...
GeneralMatrix features
The features or labels.
void Init(int32 num_classes, int32 dimension)
Allocates memory for accumulators.
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
MatrixIndexT NumCols() const
void AccStatsFromOutput(const NnetExample &eg, const CuMatrixBase< BaseFloat > &nnet_output)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void AccStats(const NnetExample &eg)
GeneralMatrixType Type() const
Returns the type of the matrix: kSparseMatrix, kCompressedMatrix or kFullMatrix.
void AcceptInputs(const Nnet &nnet, const std::vector< NnetIo > &io)
This convenience function calls AcceptInput() in turn on all the inputs in the training example...
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.
MatrixIndexT NumElements() const
Returns the number of nonzero elements.
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.
std::shared_ptr< const NnetComputation > Compile(const ComputationRequest &request)
Does the compilation and returns a const pointer to the result, which is owned by this class...
int NumArgs() const
Number of positional parameters (c.f. argc-1).
Matrix for CUDA computing.
double TotCount()
Return total count of the data.
MatrixIndexT NumCols() const
CachingOptimizingCompiler compiler_
A class representing a vector.
class NnetComputer is responsible for executing the computation described in the "computation" object...
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
void WriteStats(const std::string &stats_wxfilename, bool binary)
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
NnetLdaStatsAccumulator(BaseFloat rand_prune, const Nnet &nnet)
const SparseMatrix< BaseFloat > & GetSparseMatrix() const
Returns the contents as a SparseMatrix.
MatrixIndexT NumRows() const
Dimensions.
std::vector< NnetIo > io
"io" contains the input and output.
std::pair< MatrixIndexT, Real > * Data()
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void GetComputationRequest(const Nnet &nnet, const NnetExample &eg, bool need_model_derivative, bool store_component_stats, ComputationRequest *request)
This function takes a NnetExample (which should already have been frame-selected, if desired...
const SparseVector< Real > & Row(MatrixIndexT r) const