31 using namespace kaldi;
34 typedef kaldi::int64 int64;
37 "Propagate the features through raw neural network model " 38 "and write the output.\n" 39 "If --apply-exp=true, apply the Exp() function to the output " 40 "before writing it out.\n" 42 "Usage: nnet3-compute [options] <nnet-in> <features-rspecifier> <matrix-wspecifier>\n" 43 " e.g.: nnet3-compute final.raw scp:feats.scp ark:nnet_prediction.ark\n" 44 "See also: nnet3-compute-from-egs, nnet3-chain-compute-post\n" 45 "Note: this program does not currently make very efficient use of the GPU.\n";
53 bool apply_exp =
false, use_priors =
false;
54 std::string use_gpu =
"yes";
56 std::string ivector_rspecifier,
57 online_ivector_rspecifier,
59 int32 online_ivector_period = 0;
62 po.Register(
"ivectors", &ivector_rspecifier,
"Rspecifier for " 63 "iVectors as vectors (i.e. not estimated online); per utterance " 64 "by default, or per speaker if you provide the --utt2spk option.");
65 po.Register(
"utt2spk", &utt2spk_rspecifier,
"Rspecifier for " 66 "utt2spk option used to get ivectors per speaker");
67 po.Register(
"online-ivectors", &online_ivector_rspecifier,
"Rspecifier for " 68 "iVectors estimated online, as matrices. If you supply this," 69 " you must set the --online-ivector-period option.");
70 po.Register(
"online-ivector-period", &online_ivector_period,
"Number of frames " 71 "between iVectors in matrices supplied to the --online-ivectors " 73 po.Register(
"apply-exp", &apply_exp,
"If true, apply exp function to " 75 po.Register(
"use-gpu", &use_gpu,
76 "yes|no|optional|wait, only has effect if compiled with CUDA");
77 po.Register(
"use-priors", &use_priors,
"If true, subtract the logs of the " 78 "priors stored with the model (in this case, " 79 "a .mdl file is expected as input).");
82 CuDevice::RegisterDeviceOptions(&po);
87 if (po.NumArgs() != 3) {
93 CuDevice::Instantiate().SelectGpuId(use_gpu);
96 std::string nnet_rxfilename = po.GetArg(1),
97 feature_rspecifier = po.GetArg(2),
98 matrix_wspecifier = po.GetArg(3);
105 Input ki(nnet_rxfilename, &binary);
106 trans_model.
Read(ki.Stream(), binary);
107 am_nnet.
Read(ki.Stream(), binary);
111 Nnet &nnet = (use_priors ? am_nnet.
GetNnet() : raw_nnet);
118 priors = am_nnet.
Priors();
121 online_ivector_rspecifier);
123 ivector_rspecifier, utt2spk_rspecifier);
129 int32 num_success = 0, num_fail = 0;
130 int64 frame_count = 0;
134 for (; !feature_reader.Done(); feature_reader.Next()) {
135 std::string utt = feature_reader.Key();
137 if (features.NumRows() == 0) {
138 KALDI_WARN <<
"Zero-length utterance: " << utt;
144 if (!ivector_rspecifier.empty()) {
145 if (!ivector_reader.HasKey(utt)) {
146 KALDI_WARN <<
"No iVector available for utterance " << utt;
150 ivector = &ivector_reader.Value(utt);
153 if (!online_ivector_rspecifier.empty()) {
154 if (!online_ivector_reader.HasKey(utt)) {
155 KALDI_WARN <<
"No online iVector available for utterance " << utt;
159 online_ivectors = &online_ivector_reader.Value(utt);
166 ivector, online_ivectors,
167 online_ivector_period);
170 nnet_computer.OutputDim());
171 for (int32 t = 0; t < nnet_computer.NumFrames(); t++) {
173 nnet_computer.GetOutputForFrame(t, &row);
179 matrix_writer.Write(utt, matrix);
181 frame_count += features.NumRows();
186 CuDevice::Instantiate().PrintProfile();
188 double elapsed = timer.
Elapsed();
190 <<
"s: real-time factor assuming 100 frames/sec is " 191 << (elapsed*100.0/frame_count);
192 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 195 if (num_success != 0)
return 0;
197 }
catch(
const std::exception &e) {
198 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void CollapseModel(const CollapseModelConfig &config, Nnet *nnet)
This function modifies the neural net for efficiency, in a way that suitable to be done in test time...
This class is for when you are reading something in random access, but it may actually be stored per-...
This class enables you to do the compilation and optimization in one call, and also ensures that if t...
void SetBatchnormTestMode(bool test_mode, Nnet *nnet)
This function affects only components of type BatchNormComponent.
A templated class for writing objects to an archive or script file; see The Table concept...
const Nnet & GetNnet() const
void Read(std::istream &is, bool binary)
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...
void SetDropoutTestMode(bool test_mode, Nnet *nnet)
This function affects components of child-classes of RandomComponent.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
void Register(OptionsItf *opts)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
const VectorBase< BaseFloat > & Priors() const
A class representing a vector.
NnetOptimizeOptions optimize_config
double Elapsed() const
Returns time in seconds.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
Config class for the CollapseModel function.