Skip to content

Commit 72ba09e

Browse files
committed
integrating changes proposed by Dan,
- using GetVerboseLevel(), - avoiding 'WriteIntegerVector' for writing to KALDI_LOG by introducing: 'operator<< (std::ostream, std::vector<T>)' in kaldi-error.h
1 parent 232e1a5 commit 72ba09e

9 files changed

+29
-21
lines changed

src/base/kaldi-error.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
#include <sstream>
2828
#include <stdexcept>
2929
#include <string>
30+
#include <vector>
3031

3132
#include "base/kaldi-types.h"
3233
#include "base/kaldi-utils.h"
3334
/* Important that this file does not depend on any other kaldi headers. */
3435

3536
// By adding 'KALDI_NOEXCEPT(bool)' immediately after function declaration,
36-
// we can tell the compiler that the function must-not produce
37+
// we can tell the compiler that the function must-not produce
3738
// exceptions (true), or may produce exceptions (false):
3839
#if _MSC_VER >= 1900 || (!defined(_MSC_VER) && __cplusplus >= 201103L)
3940
#define KALDI_NOEXCEPT(Predicate) noexcept((Predicate))
@@ -54,7 +55,7 @@ namespace kaldi {
5455
/// @{
5556

5657
/***** VERBOSITY LEVEL *****/
57-
58+
5859
/// This is set by util/parse-options.{h, cc} if you set --verbose=? option.
5960
extern int32 g_kaldi_verbose_level;
6061

@@ -194,6 +195,19 @@ typedef void (*LogHandler)(const LogMessageEnvelope &envelope,
194195
/// stderr. SetLogHandler is obviously not thread safe.
195196
LogHandler SetLogHandler(LogHandler);
196197

198+
199+
/***** WRITING 'std::vector<T>' TO LOGPRINT *****/
200+
template<typename T>
201+
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
202+
os << "[ ";
203+
typename std::vector<T>::const_iterator it;
204+
for (it = v.begin(); it != v.end(); ++it) {
205+
os << *it << " ";
206+
}
207+
os << "]";
208+
return os;
209+
}
210+
197211
/// @} end "addtogroup error_group"
198212

199213
} // namespace kaldi

src/nnetbin/nnet-forward.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ int main(int argc, char *argv[]) {
194194
<< " (fps " << tot_t/time.Elapsed() << ")";
195195

196196
#if HAVE_CUDA == 1
197-
if (kaldi::g_kaldi_verbose_level >= 1) {
197+
if (GetVerboseLevel() >= 1) {
198198
CuDevice::Instantiate().PrintProfile();
199199
}
200200
#endif

src/nnetbin/nnet-train-frmshuff.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ int main(int argc, char *argv[]) {
354354

355355
// VERBOSE LOG
356356
// monitor the NN training (--verbose=2),
357-
if (kaldi::g_kaldi_verbose_level >= 2) {
357+
if (GetVerboseLevel() >= 2) {
358358
static int32 counter = 0;
359359
counter += nnet_in.NumRows();
360360
// print every 25k frames,

src/nnetbin/nnet-train-mmi-sequential.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ int main(int argc, char *argv[]) {
431431
KALDI_VLOG(1) << nnet.InfoGradient();
432432
}
433433
// Every 1000 utterances (--verbose=2),
434-
if (kaldi::g_kaldi_verbose_level >= 2) {
434+
if (GetVerboseLevel() >= 2) {
435435
if (num_done % 1000 == 0) {
436436
KALDI_VLOG(2) << nnet.InfoPropagate();
437437
KALDI_VLOG(2) << nnet.InfoBackPropagate();

src/nnetbin/nnet-train-mpe-sequential.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ int main(int argc, char *argv[]) {
366366
KALDI_VLOG(1) << nnet.InfoGradient();
367367
}
368368
// Every 1000 utterances (--verbose=2),
369-
if (kaldi::g_kaldi_verbose_level >= 2) {
369+
if (GetVerboseLevel() >= 2) {
370370
if (num_done % 1000 == 0) {
371371
KALDI_VLOG(2) << nnet.InfoPropagate();
372372
KALDI_VLOG(2) << nnet.InfoBackPropagate();

src/nnetbin/nnet-train-multistream-perutt.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,8 @@ int main(int argc, char *argv[]) {
268268
// Set the original lengths of utterances before padding,
269269
nnet.SetSeqLengths(frame_num_utt);
270270
// Show the 'utt' lengths in the VLOG[2],
271-
if (kaldi::g_kaldi_verbose_level >= 2) {
272-
WriteIntegerVector(
273-
KALDI_LOG << "frame_num_utt[" << frame_num_utt.size() << "]",
274-
false, frame_num_utt
275-
);
271+
if (GetVerboseLevel() >= 2) {
272+
KALDI_LOG << "frame_num_utt[" << frame_num_utt.size() << "]" << frame_num_utt;
276273
}
277274
// Reset all the streams (we have new sentences),
278275
nnet.ResetStreams(std::vector<int32>(frame_num_utt.size(), 1));
@@ -317,7 +314,7 @@ int main(int argc, char *argv[]) {
317314

318315
// monitor the NN training (--verbose=2),
319316
int32 F = 25000;
320-
if (kaldi::g_kaldi_verbose_level >= 3) {
317+
if (GetVerboseLevel() >= 3) {
321318
// print every 25k frames,
322319
if (tmp_frames / F != total_frames / F) {
323320
KALDI_VLOG(3) << "### After " << total_frames << " frames,";
@@ -332,7 +329,7 @@ int main(int argc, char *argv[]) {
332329
}
333330

334331
// after last model update : show what happens in network,
335-
if (kaldi::g_kaldi_verbose_level >= 1) { // vlog-1
332+
if (GetVerboseLevel() >= 1) { // vlog-1
336333
KALDI_VLOG(1) << "### After " << total_frames << " frames,";
337334
KALDI_VLOG(1) << nnet.Info();
338335
KALDI_VLOG(1) << nnet.InfoPropagate();

src/nnetbin/nnet-train-multistream.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,8 @@ int main(int argc, char *argv[]) {
346346
// pass the info about padding,
347347
nnet.SetSeqLengths(frame_num_utt);
348348
// Show the 'utt' lengths in the VLOG[2],
349-
if (kaldi::g_kaldi_verbose_level >= 2) {
350-
WriteIntegerVector(
351-
KALDI_LOG << "frame_num_utt[" << frame_num_utt.size() << "]",
352-
false, frame_num_utt
353-
);
349+
if (GetVerboseLevel() >= 2) {
350+
KALDI_LOG << "frame_num_utt[" << frame_num_utt.size() << "]" << frame_num_utt;
354351
}
355352

356353
// with new utterance we reset the history,
@@ -403,7 +400,7 @@ int main(int argc, char *argv[]) {
403400

404401
// monitor the NN training (--verbose=2),
405402
int32 F = 25000;
406-
if (kaldi::g_kaldi_verbose_level >= 3) {
403+
if (GetVerboseLevel() >= 3) {
407404
// print every 25k frames,
408405
if (tmp_frames / F != total_frames / F) {
409406
KALDI_VLOG(3) << "### After " << total_frames << " frames,";

src/nnetbin/nnet-train-perutt.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int main(int argc, char *argv[]) {
228228

229229
// VERBOSE LOG
230230
// monitor the NN training (--verbose=2),
231-
if (kaldi::g_kaldi_verbose_level >= 2) {
231+
if (GetVerboseLevel() >= 2) {
232232
static int32 counter = 0;
233233
counter += mat.NumRows();
234234
// print every 25k frames,

src/nnetbin/paste-post.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
104104
int32 num_frames = featlen_reader.Value();
105105

106106
// show which streams are non-empty,
107-
if (allow_partial && kaldi::g_kaldi_verbose_level >= 2) {
107+
if (allow_partial && GetVerboseLevel() >= 2) {
108108
std::string nonempty_streams;
109109
for (int32 s = 0; s < stream_count; s++) {
110110
if (posterior_reader[s].HasKey(utt)) {

0 commit comments

Comments
 (0)