Skip to content

Commit 9effa4a

Browse files
david-ryan-snyderdanpovey
authored andcommitted
[src] add max_warnining option to SlidingWindowCmnOptions to limit the number of times the variance flooring warning is printed (#2043)
1 parent bafb68c commit 9effa4a

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/feat/feature-functions.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ void SlidingWindowCmnInternal(const SlidingWindowCmnOptions &opts,
251251
const MatrixBase<double> &input,
252252
MatrixBase<double> *output) {
253253
opts.Check();
254-
int32 num_frames = input.NumRows(), dim = input.NumCols();
255-
256-
int32 last_window_start = -1, last_window_end = -1;
254+
int32 num_frames = input.NumRows(), dim = input.NumCols(),
255+
last_window_start = -1, last_window_end = -1,
256+
warning_count = 0;
257257
Vector<double> cur_sum(dim), cur_sumsq(dim);
258258

259259
for (int32 t = 0; t < num_frames; t++) {
@@ -323,8 +323,20 @@ void SlidingWindowCmnInternal(const SlidingWindowCmnOptions &opts,
323323
// around their own mean.
324324
int32 num_floored = variance.ApplyFloor(1.0e-10);
325325
if (num_floored > 0 && num_frames > 1) {
326-
KALDI_WARN << "Flooring variance When normalizing variance, floored " << num_floored
327-
<< " elements; num-frames was " << window_frames;
326+
if (opts.max_warnings == warning_count) {
327+
KALDI_WARN << "Suppressing the remaining variance flooring "
328+
<< "warnings. Run program with --max-warnings=-1 to "
329+
<< "see all warnings.";
330+
}
331+
// If opts.max_warnings is a negative number, we won't restrict the
332+
// number of times that the warning is printed out.
333+
else if (opts.max_warnings < 0
334+
|| opts.max_warnings > warning_count) {
335+
KALDI_WARN << "Flooring when normalizing variance, floored "
336+
<< num_floored << " elements; num-frames was "
337+
<< window_frames;
338+
}
339+
warning_count++;
328340
}
329341
variance.ApplyPow(-0.5); // get inverse standard deviation.
330342
output_frame.MulElements(variance);
@@ -339,7 +351,7 @@ void SlidingWindowCmn(const SlidingWindowCmnOptions &opts,
339351
MatrixBase<BaseFloat> *output) {
340352
KALDI_ASSERT(SameDim(input, *output) && input.NumRows() > 0);
341353
Matrix<double> input_dbl(input), output_dbl(input.NumRows(), input.NumCols());
342-
// calll double-precision version
354+
// call double-precision version
343355
SlidingWindowCmnInternal(opts, input_dbl, &output_dbl);
344356
output->CopyFromMat(output_dbl);
345357
}

src/feat/feature-functions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ void InitIdftBases(int32 n_bases, int32 dimension, Matrix<BaseFloat> *mat_out);
158158
struct SlidingWindowCmnOptions {
159159
int32 cmn_window;
160160
int32 min_window;
161+
int32 max_warnings;
161162
bool normalize_variance;
162163
bool center;
163164

164165
SlidingWindowCmnOptions():
165166
cmn_window(600),
166167
min_window(100),
168+
max_warnings(5),
167169
normalize_variance(false),
168170
center(false) { }
169171

@@ -173,6 +175,8 @@ struct SlidingWindowCmnOptions {
173175
opts->Register("min-cmn-window", &min_window, "Minimum CMN window "
174176
"used at start of decoding (adds latency only at start). "
175177
"Only applicable if center == false, ignored if center==true");
178+
opts->Register("max-warnings", &max_warnings, "Maximum warnings to report "
179+
"per utterance. 0 to disable, -1 to show all.");
176180
opts->Register("norm-vars", &normalize_variance, "If true, normalize "
177181
"variance to one."); // naming this as in apply-cmvn.cc
178182
opts->Register("center", &center, "If true, use a window centered on the "

0 commit comments

Comments
 (0)