32 class NnetComputerFromEg {
41 bool need_backprop =
false, store_stats =
false;
63 int main(
int argc,
char *argv[]) {
65 using namespace kaldi;
68 typedef kaldi::int64 int64;
71 "Read input nnet discriminative training examples, and compute the " 72 "output for each one. This program is similar to " 73 "nnet3-compute-from-egs, but works with discriminative egs. \n" 74 "If --apply-exp=true, apply the Exp() function to the output before writing\n" 76 "Note: This program uses only the input; it does not do forward-backward\n" 77 "over the lattice. See nnet3-discriminative-compute-objf for that.\n" 79 "Usage: nnet3-discriminative-compute-from-egs [options] <raw-nnet-in> <training-examples-in> <matrices-out>\n" 81 "nnet3-discriminative-compute-from-egs --apply-exp=true 0.raw ark:1.degs ark:- | matrix-sum-rows ark:- ... \n" 82 "See also: nnet3-compute nnet3-compute-from-egs\n";
84 bool binary_write =
true,
86 std::string use_gpu =
"yes";
89 po.
Register(
"binary", &binary_write,
"Write output in binary mode");
90 po.
Register(
"apply-exp", &apply_exp,
"If true, apply exp function to " 93 "yes|no|optional|wait, only has effect if compiled with CUDA");
103 CuDevice::Instantiate().SelectGpuId(use_gpu);
106 std::string nnet_rxfilename = po.
GetArg(1),
107 examples_rspecifier = po.
GetArg(2),
108 matrix_wspecifier = po.
GetArg(3);
120 for (; !example_reader.
Done(); example_reader.
Next(), num_egs++) {
126 for (int32
i = 0;
i < disc_eg.
outputs.size();
i++) {
133 computer.Compute(eg, &output);
137 matrix_writer.
Write(example_reader.
Key(), output);
140 CuDevice::Instantiate().PrintProfile();
142 KALDI_LOG <<
"Processed " << num_egs <<
" examples.";
144 }
catch(
const std::exception &e) {
145 std::cerr << e.what() <<
'\n';
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void CopyToMat(MatrixBase< OtherReal > *dst, MatrixTransposeType trans=kNoTrans) const
CachingOptimizingCompiler compiler_
int main(int argc, char *argv[])
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.
This class enables you to do the compilation and optimization in one call, and also ensures that if t...
A templated class for writing objects to an archive or script file; see The Table concept...
std::vector< Index > indexes
"indexes" is a vector the same length as features.NumRows(), explaining the meaning of each row of th...
void Compute(const NnetExample &eg, Matrix< BaseFloat > *output)
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
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.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
NnetComputerFromEg(const Nnet &nnet)
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.
MatrixIndexT NumCols() const
class NnetComputer is responsible for executing the computation described in the "computation" object...
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
std::vector< NnetIo > inputs
'inputs' contains the input to the network– normally just it has just one element called "input"...
std::vector< NnetDiscriminativeSupervision > outputs
'outputs' contains the sequence output supervision.
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).
std::string name
the name of the input in the neural net; in simple setups it will just be "input".
MatrixIndexT NumRows() const
Dimensions.
std::vector< NnetIo > io
"io" contains the input and output.
NnetDiscriminativeExample is like NnetExample, but specialized for sequence training.
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...