OnlineIvectorFeature is an online feature-extraction class that's responsible for extracting iVectors from raw features such as MFCC, PLP or filterbank. More...
#include <online-ivector-feature.h>
Public Member Functions | |
OnlineIvectorFeature (const OnlineIvectorExtractionInfo &info, OnlineFeatureInterface *base_feature) | |
Constructor. More... | |
virtual int32 | Dim () const |
Dim() will return the iVector dimension. More... | |
virtual bool | IsLastFrame (int32 frame) const |
Returns true if this is the last frame. More... | |
virtual int32 | NumFramesReady () const |
returns the feature dimension. More... | |
virtual BaseFloat | FrameShiftInSeconds () const |
virtual void | GetFrame (int32 frame, VectorBase< BaseFloat > *feat) |
Gets the feature vector for this frame. More... | |
void | SetAdaptationState (const OnlineIvectorExtractorAdaptationState &adaptation_state) |
Set the adaptation state to a particular value, e.g. More... | |
void | GetAdaptationState (OnlineIvectorExtractorAdaptationState *adaptation_state) const |
Get the adaptation state; you may want to call this before destroying this object, to get adaptation state that can be used to improve decoding of later utterances of this speaker. More... | |
virtual | ~OnlineIvectorFeature () |
BaseFloat | UbmLogLikePerFrame () const |
BaseFloat | ObjfImprPerFrame () const |
BaseFloat | NumFrames () const |
void | UpdateFrameWeights (const std::vector< std::pair< int32, BaseFloat > > &delta_weights) |
Public Member Functions inherited from OnlineFeatureInterface | |
virtual void | GetFrames (const std::vector< int32 > &frames, MatrixBase< BaseFloat > *feats) |
This is like GetFrame() but for a collection of frames. More... | |
virtual | ~OnlineFeatureInterface () |
Virtual destructor. More... | |
Private Member Functions | |
void | UpdateStatsForFrames (const std::vector< std::pair< int32, BaseFloat > > &frame_weights) |
BaseFloat | GetMinPost (BaseFloat weight) const |
void | UpdateStatsUntilFrame (int32 frame) |
void | UpdateStatsUntilFrameWeighted (int32 frame) |
void | PrintDiagnostics () const |
Private Attributes | |
const OnlineIvectorExtractionInfo & | info_ |
OnlineFeatureInterface * | base_ |
OnlineFeatureInterface * | lda_ |
OnlineCmvn * | cmvn_ |
OnlineFeatureInterface * | lda_normalized_ |
std::vector< OnlineFeatureInterface * > | to_delete_ |
OnlineIvectorEstimationStats | ivector_stats_ |
the iVector estimation stats More... | |
int32 | num_frames_stats_ |
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and put in ivector_stats_. More... | |
std::priority_queue< std::pair< int32, BaseFloat >, std::vector< std::pair< int32, BaseFloat > >, std::greater< std::pair< int32, BaseFloat > > > | delta_weights_ |
delta_weights_ is written to by UpdateFrameWeights, in the case where the iVector estimation is silence-weighted using the decoder traceback. More... | |
std::vector< BaseFloat > | current_frame_weight_debug_ |
this is only used for validating that the frame-weighting code is not buggy. More... | |
bool | delta_weights_provided_ |
delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it's used to detect wrong usage of this class. More... | |
bool | updated_with_no_delta_weights_ |
The following is also used to detect wrong usage of this class; it's set to true if UpdateStatsUntilFrame() was ever called. More... | |
int32 | most_recent_frame_with_weight_ |
if delta_weights_ was ever called, this keeps track of the most recent frame that ever had a weight. More... | |
double | tot_ubm_loglike_ |
The following is only needed for diagnostics. More... | |
Vector< double > | current_ivector_ |
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frames_stats_ and t % info_.ivector_period == 0. More... | |
std::vector< Vector< BaseFloat > *> | ivectors_history_ |
if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_.ivector_period frames so that GetFrame() can return the iVector that was active on that frame. More... | |
OnlineIvectorFeature is an online feature-extraction class that's responsible for extracting iVectors from raw features such as MFCC, PLP or filterbank.
Internally it processes the raw features using two different pipelines, one online-CMVN+splice+LDA, and one just splice+LDA. It gets GMM posteriors from the CMVN-normalized features, and with those and the unnormalized features it obtains iVectors.
Definition at line 256 of file online-ivector-feature.h.
|
explicit |
Constructor.
base_feature is for example raw MFCC or PLP or filterbank features, whatever was used to train the iVector extractor. "info" contains all the configuration information as well as things like the iVector extractor that we won't be modifying. Caution: the class keeps a const reference to "info", so don't delete it while this class or others copied from it still exist.
Definition at line 399 of file online-ivector-feature.cc.
References OnlineIvectorExtractionInfo::Check(), OnlineIvectorFeature::cmvn_, OnlineIvectorExtractionInfo::cmvn_opts, OnlineIvectorFeature::current_ivector_, OnlineIvectorExtractionInfo::extractor, OnlineIvectorExtractionInfo::global_cmvn_stats, OnlineIvectorFeature::info_, IvectorExtractor::IvectorDim(), KALDI_ASSERT, OnlineIvectorFeature::lda_, OnlineIvectorExtractionInfo::lda_mat, OnlineIvectorFeature::lda_normalized_, IvectorExtractor::PriorOffset(), Vector< Real >::Resize(), OnlineIvectorExtractionInfo::splice_opts, and OnlineIvectorFeature::to_delete_.
|
virtual |
Definition at line 377 of file online-ivector-feature.cc.
References rnnlm::i.
|
virtual |
Dim() will return the iVector dimension.
Implements OnlineFeatureInterface.
Definition at line 147 of file online-ivector-feature.cc.
Referenced by main().
|
virtual |
Implements OnlineFeatureInterface.
Definition at line 165 of file online-ivector-feature.cc.
void GetAdaptationState | ( | OnlineIvectorExtractorAdaptationState * | adaptation_state | ) | const |
Get the adaptation state; you may want to call this before destroying this object, to get adaptation state that can be used to improve decoding of later utterances of this speaker.
Definition at line 386 of file online-ivector-feature.cc.
References OnlineIvectorExtractorAdaptationState::cmvn_state, OnlineIvectorExtractorAdaptationState::ivector_stats, and OnlineIvectorExtractorAdaptationState::LimitFrames().
Referenced by OnlineNnet2FeaturePipeline::GetAdaptationState(), and main().
|
virtual |
Gets the feature vector for this frame.
Before calling this for a given frame, it is assumed that you called NumFramesReady() and it returned a number greater than "frame". Otherwise this call will likely crash with an assert failure. This function is not declared const, in case there is some kind of caching going on, but most of the time it shouldn't modify the class.
Implements OnlineFeatureInterface.
Definition at line 327 of file online-ivector-feature.cc.
References VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, and KALDI_VLOG.
Referenced by main().
Definition at line 188 of file online-ivector-feature.cc.
Returns true if this is the last frame.
Frame indices are zero-based, so the first frame is zero. IsLastFrame(-1) will return false, unless the file is empty (which is a case that I'm not sure all the code will handle, so be careful). This function may return false for some frame if we haven't yet decided to terminate decoding, but later true if we decide to terminate decoding. This function exists mainly to correctly handle end effects in feature extraction, and is not a mechanism to determine how many frames are in the decodable object (as it used to be, and for backward compatibility, still is, in the Decodable interface).
Implements OnlineFeatureInterface.
Definition at line 151 of file online-ivector-feature.cc.
|
inline |
Definition at line 307 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::UbmLogLikePerFrame().
|
virtual |
returns the feature dimension.
Returns the total number of frames, since the start of the utterance, that are now available. In an online-decoding context, this will likely increase with time as more data becomes available.
Implements OnlineFeatureInterface.
Definition at line 160 of file online-ivector-feature.cc.
References KALDI_ASSERT.
Referenced by SingleUtteranceNnet2DecoderThreaded::RunNnetEvaluationInternal().
BaseFloat ObjfImprPerFrame | ( | ) | const |
Definition at line 460 of file online-ivector-feature.cc.
References OnlineIvectorFeature::current_ivector_, OnlineIvectorFeature::ivector_stats_, and OnlineIvectorEstimationStats::ObjfChange().
Referenced by main().
|
private |
Definition at line 357 of file online-ivector-feature.cc.
References KALDI_VLOG, VectorBase< Real >::Norm(), and kaldi::NumFrames().
void SetAdaptationState | ( | const OnlineIvectorExtractorAdaptationState & | adaptation_state | ) |
Set the adaptation state to a particular value, e.g.
reflecting previous utterances of the same speaker; this will generally be called after constructing a new instance of this class.
Definition at line 445 of file online-ivector-feature.cc.
References OnlineIvectorFeature::cmvn_, OnlineIvectorExtractorAdaptationState::cmvn_state, OnlineIvectorExtractorAdaptationState::ivector_stats, OnlineIvectorFeature::ivector_stats_, OnlineIvectorEstimationStats::IvectorDim(), KALDI_ASSERT, OnlineIvectorFeature::num_frames_stats_, and OnlineCmvn::SetState().
Referenced by main(), and OnlineNnet2FeaturePipeline::SetAdaptationState().
BaseFloat UbmLogLikePerFrame | ( | ) | const |
Definition at line 455 of file online-ivector-feature.cc.
References OnlineIvectorFeature::NumFrames(), and OnlineIvectorFeature::tot_ubm_loglike_.
Referenced by main().
Definition at line 169 of file online-ivector-feature.cc.
References rnnlm::i, and KALDI_ASSERT.
Referenced by main(), SingleUtteranceNnet2DecoderThreaded::RunNnetEvaluationInternal(), and OnlineNnet2FeaturePipeline::UpdateFrameWeights().
|
private |
Definition at line 201 of file online-ivector-feature.cc.
References rnnlm::i, rnnlm::j, kaldi::kUndefined, kaldi::MergePairVectorSumming(), MatrixBase< Real >::Row(), and kaldi::VectorToPosteriorEntry().
|
private |
Definition at line 248 of file online-ivector-feature.cc.
References KALDI_ASSERT.
|
private |
Definition at line 281 of file online-ivector-feature.cc.
References KALDI_ASSERT.
|
private |
Definition at line 352 of file online-ivector-feature.h.
|
private |
Definition at line 356 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::OnlineIvectorFeature(), and OnlineIvectorFeature::SetAdaptationState().
|
private |
this is only used for validating that the frame-weighting code is not buggy.
Definition at line 385 of file online-ivector-feature.h.
|
private |
Most recently estimated iVector, will have been estimated at the greatest time t where t <= num_frames_stats_ and t % info_.ivector_period == 0.
Definition at line 404 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::ObjfImprPerFrame(), and OnlineIvectorFeature::OnlineIvectorFeature().
|
private |
delta_weights_ is written to by UpdateFrameWeights, in the case where the iVector estimation is silence-weighted using the decoder traceback.
Its elements are consumed by UpdateStatsUntilFrameWeighted(). We provide std::greater<std::pair<int32, BaseFloat> > > as the comparison type (default is std::less) so that the lowest-numbered frame, not the highest-numbered one, will be returned by top().
Definition at line 382 of file online-ivector-feature.h.
|
private |
delta_weights_provided_ is set to true if UpdateFrameWeights was ever called; it's used to detect wrong usage of this class.
Definition at line 389 of file online-ivector-feature.h.
|
private |
Definition at line 350 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::OnlineIvectorFeature().
|
private |
the iVector estimation stats
Definition at line 364 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::ObjfImprPerFrame(), and OnlineIvectorFeature::SetAdaptationState().
if info_.use_most_recent_ivector == false, we need to store the iVector we estimated each info_.ivector_period frames so that GetFrame() can return the iVector that was active on that frame.
ivectors_history_[i] contains the iVector we estimated on frame t = i * info_.ivector_period.
Definition at line 411 of file online-ivector-feature.h.
|
private |
Definition at line 355 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::OnlineIvectorFeature().
|
private |
Definition at line 357 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::OnlineIvectorFeature().
|
private |
if delta_weights_ was ever called, this keeps track of the most recent frame that ever had a weight.
It's mostly for detecting errors.
Definition at line 396 of file online-ivector-feature.h.
|
private |
num_frames_stats_ is the number of frames of data we have already accumulated from this utterance and put in ivector_stats_.
Each frame t < num_frames_stats_ is in the stats. In case you are doing the silence-weighted iVector estimation, with UpdateFrameWeights() being called, this variable is still used but you may later have to revisit earlier frames to adjust their weights... see the code.
Definition at line 372 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::SetAdaptationState().
|
private |
Definition at line 361 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::OnlineIvectorFeature().
|
private |
The following is only needed for diagnostics.
Definition at line 399 of file online-ivector-feature.h.
Referenced by OnlineIvectorFeature::UbmLogLikePerFrame().
|
private |
The following is also used to detect wrong usage of this class; it's set to true if UpdateStatsUntilFrame() was ever called.
Definition at line 392 of file online-ivector-feature.h.