29 using namespace kaldi;
33 "Apply I-smoothing to statistics, e.g. for discriminative training\n" 34 "Usage: gmm-ismooth-stats [options] [--smooth-from-model] [<src-stats-in>|<src-model-in>] <dst-stats-in> <stats-out>\n" 35 "e.g.: gmm-ismooth-stats --tau=100 ml.acc num.acc smoothed.acc\n" 36 "or: gmm-ismooth-stats --tau=50 --smooth-from-model 1.mdl num.acc smoothed.acc\n" 37 "or: gmm-ismooth-stats --tau=100 num.acc num.acc smoothed.acc\n";
39 bool binary_write =
false;
40 bool smooth_from_model =
false;
44 po.Register(
"binary", &binary_write,
"Write output in binary mode");
45 po.Register(
"smooth-from-model", &smooth_from_model,
"If true, " 46 "expect first argument to be a model file");
47 po.Register(
"tau", &tau,
"Tau value for I-smoothing");
51 if (po.NumArgs() != 3) {
56 std::string src_stats_or_model_filename = po.GetArg(1),
57 dst_stats_filename = po.GetArg(2),
58 stats_out_filename = po.GetArg(3);
60 double tot_count_before, tot_count_after;
62 if (src_stats_or_model_filename == dst_stats_filename) {
68 Input ki(dst_stats_filename, &binary);
69 transition_accs.
Read(ki.Stream(), binary);
70 stats.
Read(ki.Stream(), binary,
true);
75 Output ko(stats_out_filename, binary_write);
76 transition_accs.
Write(ko.Stream(), binary_write);
77 stats.
Write(ko.Stream(), binary_write);
78 }
else if (smooth_from_model) {
85 Input ki(src_stats_or_model_filename, &binary);
86 trans_model.
Read(ki.Stream(), binary);
87 am_gmm.
Read(ki.Stream(), binary);
91 Input ki(dst_stats_filename, &binary);
92 dst_transition_accs.
Read(ki.Stream(), binary);
93 dst_stats.
Read(ki.Stream(), binary,
true);
98 Output ko(stats_out_filename, binary_write);
99 dst_transition_accs.
Write(ko.Stream(), binary_write);
100 dst_stats.
Write(ko.Stream(), binary_write);
108 Input ki(src_stats_or_model_filename, &binary);
109 src_transition_accs.
Read(ki.Stream(), binary);
110 src_stats.
Read(ki.Stream(), binary,
true);
114 Input ki(dst_stats_filename, &binary);
115 dst_transition_accs.
Read(ki.Stream(), binary);
116 dst_stats.
Read(ki.Stream(), binary,
true);
122 Output ko(stats_out_filename, binary_write);
123 dst_transition_accs.
Write(ko.Stream(), binary_write);
124 dst_stats.
Write(ko.Stream(), binary_write);
126 KALDI_LOG <<
"Smoothed stats with tau = " << tau <<
", count changed from " 127 << tot_count_before <<
" to " << tot_count_after;
128 }
catch(
const std::exception &e) {
129 std::cerr << e.what() <<
'\n';
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void IsmoothStatsAmDiagGmmFromModel(const AmDiagGmm &src_model, double tau, AccumAmDiagGmm *dst_stats)
This version of the I-smoothing function takes a model as input.
void Read(std::istream &is, bool binary)
void IsmoothStatsAmDiagGmm(const AccumAmDiagGmm &src_stats, double tau, AccumAmDiagGmm *dst_stats)
Smooth "dst_stats" with "src_stats".
BaseFloat TotStatsCount() const
void Read(std::istream &in_stream, bool binary, bool add=false)
#define KALDI_ASSERT(cond)
void Write(std::ostream &out_stream, bool binary) const
void Read(std::istream &in_stream, bool binary)
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.