Skip to content

Commit

Permalink
[src] Making ivector extractor tolerate dim mismatch due to pitch (ka…
Browse files Browse the repository at this point in the history
  • Loading branch information
danpovey committed Nov 21, 2019
1 parent 249e2b2 commit 59255ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/online2/online-ivector-feature.cc
Expand Up @@ -67,6 +67,13 @@ void OnlineIvectorExtractionInfo::Init(
this->Check();
}

int32 OnlineIvectorExtractionInfo::ExpectedFeatureDim() const {
int32 num_splice = 1 + splice_opts.left_context + splice_opts.right_context,
full_dim = diag_ubm.Dim();
KALDI_ASSERT(full_dim % num_splice == 0 &&
"Something went wrong getting the feature dimension");
return full_dim / num_splice;
}

void OnlineIvectorExtractionInfo::Check() const {
KALDI_ASSERT(global_cmvn_stats.NumRows() == 2);
Expand Down
2 changes: 2 additions & 0 deletions src/online2/online-ivector-feature.h
Expand Up @@ -193,6 +193,8 @@ struct OnlineIvectorExtractionInfo {

void Init(const OnlineIvectorExtractionConfig &config);

int32 ExpectedFeatureDim() const;

// This constructor creates a version of this object where everything
// is empty or zero.
OnlineIvectorExtractionInfo();
Expand Down
13 changes: 12 additions & 1 deletion src/online2bin/ivector-extract-online2.cc
Expand Up @@ -94,6 +94,7 @@ int main(int argc, char *argv[]) {
RandomAccessBaseFloatVectorReader frame_weights_reader(frame_weights_rspecifier);
BaseFloatMatrixWriter ivector_writer(ivectors_wspecifier);

bool warned_dim = false;
for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
std::string spk = spk2utt_reader.Key();
const std::vector<std::string> &uttlist = spk2utt_reader.Value();
Expand All @@ -108,7 +109,17 @@ int main(int argc, char *argv[]) {
}
const Matrix<BaseFloat> &feats = feature_reader.Value(utt);

OnlineMatrixFeature matrix_feature(feats);
int32 feat_dim = feats.NumCols();
if (feat_dim == ivector_info.ExpectedFeatureDim() + 3) {
if (!warned_dim) {
KALDI_WARN << "Feature dimension is too large by 3, assuming there are "
"pitch features and removing the last 3 dims.";
warned_dim = true;
}
feat_dim -= 3;
}

OnlineMatrixFeature matrix_feature(feats.ColRange(0, feat_dim));

OnlineIvectorFeature ivector_feature(ivector_info,
&matrix_feature);
Expand Down

0 comments on commit 59255ae

Please sign in to comment.