32 using namespace kaldi;
35 typedef kaldi::int64 int64;
38 "Does the neural net computation for each file of input features, and\n" 39 "outputs as a matrix the result. Used mostly for debugging.\n" 40 "Note: if you want it to apply a log (e.g. for log-likelihoods), use\n" 43 "Usage: nnet-am-compute [options] <model-in> <feature-rspecifier> " 44 "<feature-or-loglikes-wspecifier>\n" 45 "See also: nnet-compute, nnet-logprob\n";
47 bool divide_by_priors =
false;
48 bool apply_log =
false;
49 bool pad_input =
true;
50 std::string use_gpu =
"no";
53 po.Register(
"divide-by-priors", ÷_by_priors,
"If true, " 54 "divide by the priors stored in the model and re-normalize, apply-log may follow");
55 po.Register(
"apply-log", &apply_log,
"Apply a log to the result of the computation " 56 "before outputting.");
57 po.Register(
"pad-input", &pad_input,
"If true, duplicate the first and last frames " 58 "of input features as required for temporal context, to prevent #frames " 59 "of output being less than those of input.");
60 po.Register(
"use-gpu", &use_gpu,
61 "yes|no|optional|wait, only has effect if compiled with CUDA");
62 po.Register(
"chunk-size", &chunk_size,
"Process the feature matrix in chunks. " 63 "This is useful when processing large feature files in the GPU. " 64 "If chunk-size > 0, pad-input must be true.");
68 if (po.NumArgs() != 3) {
76 CuDevice::Instantiate().SelectGpuId(use_gpu);
79 std::string nnet_rxfilename = po.GetArg(1),
80 features_rspecifier = po.GetArg(2),
81 features_or_loglikes_wspecifier = po.GetArg(3);
87 Input ki(nnet_rxfilename, &binary_read);
88 trans_model.
Read(ki.Stream(), binary_read);
89 am_nnet.
Read(ki.Stream(), binary_read);
94 int64 num_done = 0, num_frames = 0;
98 "Priors in neural network not set up.");
99 inv_priors.ApplyPow(-1.0);
104 for (; !feature_reader.Done(); feature_reader.Next()) {
105 std::string utt = feature_reader.Key();
111 if (output_frames <= 0) {
112 KALDI_WARN <<
"Skipping utterance " << utt <<
" because output " 113 <<
"would be empty.";
120 if (chunk_size > 0 && chunk_size < feats.
NumRows()) {
125 cu_output.Swap(&output);
127 if (divide_by_priors) {
128 output.MulColsVec(inv_priors);
130 for (int32
i = 0;
i < output.NumRows();
i++) {
134 KALDI_WARN <<
"Bad sum of probabilities " << p;
136 frame.Scale(1.0 / p);
142 output.ApplyFloor(1.0e-20);
145 writer.Write(utt, output);
150 CuDevice::Instantiate().PrintProfile();
153 KALDI_LOG <<
"Processed " << num_done <<
" feature files, " 154 << num_frames <<
" frames of input were processed.";
156 return (num_done == 0 ? 1 : 0);
157 }
catch(
const std::exception &e) {
158 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int32 LeftContext() const
Returns the left-context summed over all the Components...
void Read(std::istream &is, bool binary)
int32 OutputDim() const
The output dimension of the network – typically the number of pdfs.
A templated class for writing objects to an archive or script file; see The Table concept...
void NnetComputationChunked(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input, int32 chunk_size, CuMatrixBase< BaseFloat > *output)
Does the basic neural net computation, on a sequence of data (e.g.
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void NnetComputation(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input, bool pad_input, CuMatrixBase< BaseFloat > *output)
Does the basic neural net computation, on a sequence of data (e.g.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
const VectorBase< BaseFloat > & Priors() const
int32 RightContext() const
Returns the right-context summed over all the Components...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
const Nnet & GetNnet() const