Commit 186340ac authored by Tanel Alumae's avatar Tanel Alumae
Browse files

trunk: implemented Read/Write for OnlineIvectorExtractorAdaptationState and...

trunk: implemented Read/Write for OnlineIvectorExtractorAdaptationState and some classes that it uses

git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@4582 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
parent 18085e41
......@@ -107,6 +107,30 @@ OnlineCmvnState::OnlineCmvnState(const OnlineCmvnState &other):
global_cmvn_stats(other.global_cmvn_stats),
frozen_state(other.frozen_state) { }
void OnlineCmvnState::Write(std::ostream &os, bool binary) const {
WriteToken(os, binary, "<OnlineCmvnState>"); // magic string.
WriteToken(os, binary, "<SpeakerCmvnStats>");
speaker_cmvn_stats.Write(os, binary);
WriteToken(os, binary, "<GlobalCmvnStats>");
global_cmvn_stats.Write(os, binary);
WriteToken(os, binary, "<FrozenState>");
frozen_state.Write(os, binary);
WriteToken(os, binary, "</OnlineCmvnState>");
}
void OnlineCmvnState::Read(std::istream &is, bool binary) {
ExpectToken(is, binary, "<OnlineCmvnState>"); // magic string.
ExpectToken(is, binary, "<SpeakerCmvnStats>");
speaker_cmvn_stats.Read(is, binary);
ExpectToken(is, binary, "<GlobalCmvnStats>");
global_cmvn_stats.Read(is, binary);
ExpectToken(is, binary, "<FrozenState>");
frozen_state.Read(is, binary);
ExpectToken(is, binary, "</OnlineCmvnState>");
}
OnlineCmvn::OnlineCmvn(const OnlineCmvnOptions &opts,
const OnlineCmvnState &cmvn_state,
OnlineFeatureInterface *src):
......
......@@ -226,6 +226,9 @@ struct OnlineCmvnState {
// Copy constructor
OnlineCmvnState(const OnlineCmvnState &other);
void Write(std::ostream &os, bool binary) const;
void Read(std::istream &is, bool binary);
// Use the default assignment operator.
};
......
......@@ -557,6 +557,31 @@ void OnlineIvectorEstimationStats::Scale(double scale) {
quadratic_term_.AddToDiag(1.0 - scale);
}
void OnlineIvectorEstimationStats::Write(std::ostream &os, bool binary) const {
WriteToken(os, binary, "<OnlineIvectorEstimationStats>"); // magic string.
WriteToken(os, binary, "<PriorOffset>");
WriteBasicType(os, binary, prior_offset_);
WriteToken(os, binary, "<NumFrames>");
WriteBasicType(os, binary, num_frames_);
WriteToken(os, binary, "<QuadraticTerm>");
quadratic_term_.Write(os, binary);
WriteToken(os, binary, "<LinearTerm>");
linear_term_.Write(os, binary);
WriteToken(os, binary, "</OnlineIvectorEstimationStats>");
}
void OnlineIvectorEstimationStats::Read(std::istream &is, bool binary) {
ExpectToken(is, binary, "<OnlineIvectorEstimationStats>"); // magic string.
ExpectToken(is, binary, "<PriorOffset>");
ReadBasicType(is, binary, &prior_offset_);
ExpectToken(is, binary, "<NumFrames>");
ReadBasicType(is, binary, &num_frames_);
ExpectToken(is, binary, "<QuadraticTerm>");
quadratic_term_.Read(is, binary);
ExpectToken(is, binary, "<LinearTerm>");
linear_term_.Read(is, binary);
ExpectToken(is, binary, "</OnlineIvectorEstimationStats>");
}
void OnlineIvectorEstimationStats::GetIvector(
int32 num_cg_iters,
......
......@@ -344,6 +344,9 @@ class OnlineIvectorEstimationStats {
/// apply the scaling to the prior term.
void Scale(double scale);
void Write(std::ostream &os, bool binary) const;
void Read(std::istream &is, bool binary);
// Use the default assignment operator
protected:
/// Returns objective function per frame, at this iVector value.
......
......@@ -114,6 +114,24 @@ void OnlineIvectorExtractorAdaptationState::LimitFrames(
}
}
void OnlineIvectorExtractorAdaptationState::Write(std::ostream &os, bool binary) const {
WriteToken(os, binary, "<OnlineIvectorExtractorAdaptationState>"); // magic string.
WriteToken(os, binary, "<CmvnState>");
cmvn_state.Write(os, binary);
WriteToken(os, binary, "<IvectorStats>");
ivector_stats.Write(os, binary);
WriteToken(os, binary, "</OnlineIvectorExtractorAdaptationState>");
}
void OnlineIvectorExtractorAdaptationState::Read(std::istream &is, bool binary) {
ExpectToken(is, binary, "<OnlineIvectorExtractorAdaptationState>"); // magic string.
ExpectToken(is, binary, "<CmvnState>");
cmvn_state.Read(is, binary);
ExpectToken(is, binary, "<IvectorStats>");
ivector_stats.Read(is, binary);
ExpectToken(is, binary, "</OnlineIvectorExtractorAdaptationState>");
}
int32 OnlineIvectorFeature::Dim() const {
return info_.extractor.IvectorDim();
}
......
......@@ -205,6 +205,9 @@ struct OnlineIvectorExtractorAdaptationState {
/// by that factor.]
void LimitFrames(BaseFloat max_remembered_frames,
BaseFloat posterior_scale);
void Write(std::ostream &os, bool binary) const;
void Read(std::istream &is, bool binary);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment