|
kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
|
Online (running) cepstral mean and optional variance normalization. More...
#include <online-cmvn.h>
Public Member Functions | |
| OnlineCmvn (const OnlineCmvnOptions &opts, const OnlineCmvnState &state) | |
| Construct with options and adaptation state. | |
| int32_t | Dim () const |
| Feature dimension (dim of the global stats minus one). | |
| int32_t | NumFramesAccepted () const |
| Number of frames accepted so far. | |
| VectorF | AcceptFeature (const float *feat, int32_t dim) |
| Push one raw feature frame; return the normalized frame. | |
| VectorF | AcceptFeature (const VectorF &feat) |
| Same as AcceptFeature(const float *, int32_t). | |
| MatrixF | AcceptFeatures (const MatrixF &feats) |
| Push a batch of raw feature frames. | |
| void | Freeze () |
| Freeze the normalization at the current frame. | |
| OnlineCmvnState | GetState () const |
| Return the adaptation state for the next utterance. | |
Static Public Member Functions | |
| static void | SmoothOnlineCmvnStats (const MatrixD &speaker_stats, const MatrixD &global_stats, const OnlineCmvnOptions &opts, MatrixD *stats) |
| Smooth window stats with speaker and global stats. | |
Online (running) cepstral mean and optional variance normalization.
A port of kaldi's OnlineCmvn (kaldi/src/feat/online-feature.h), push-style: feed raw feature frames one by one and get the normalized frames back (kaldi's version is a pull-style filter in an OnlineFeatureInterface chain).
Unlike the offline CMVN of feature-cmvn.h (which uses the whole utterance), this class looks only at the past. In the middle of a long utterance it accumulates stats from the previous cmn_window frames (default 600, i.e. 6 seconds) and normalizes the current frame with them. At the beginning of an utterance the window stats are augmented ("smoothed") with up to speaker_frames frames of speaker stats from previous utterances and up to global_frames frames of global stats, so the first frames are normalized against a reasonable distribution.
The frame being normalized is included in the stats that normalize it (exactly like kaldi). Variance normalization floors the variance at 1e-20.
Example:
| knf::OnlineCmvn::OnlineCmvn | ( | const OnlineCmvnOptions & | opts, |
| const OnlineCmvnState & | state ) |
Construct with options and adaptation state.
| opts | [in] The options (defaults match kaldi). |
| state | [in] Adaptation state; state.global_cmvn_stats must be a 2 x (dim+1) matrix. speaker_cmvn_stats and frozen_state may be empty; if frozen_state is set, the normalization is frozen from the start (see Freeze()). |
| VectorF knf::OnlineCmvn::AcceptFeature | ( | const float * | feat, |
| int32_t | dim ) |
Push one raw feature frame; return the normalized frame.
| feat | [in] Pointer to dim raw feature values. |
| dim | [in] Feature dimension (must equal Dim()). |
The frame is normalized with stats that include the frame itself (like kaldi). The raw frame also updates the speaker stats used by GetState().
Push a batch of raw feature frames.
| feats | [in] Raw features, rows are frames, [T, dim]. |
|
inline |
Feature dimension (dim of the global stats minus one).
| void knf::OnlineCmvn::Freeze | ( | ) |
Freeze the normalization at the current frame.
From now on frames are normalized with the current (smoothed) stats and the running stats stop updating. The frozen state is part of GetState() so later utterances of the speaker keep the same normalization (kaldi uses this to estimate fMLLR on top of a fixed CMVN).
| OnlineCmvnState knf::OnlineCmvn::GetState | ( | ) | const |
Return the adaptation state for the next utterance.
Contains the speaker stats accumulated over all accepted frames (plus any incoming speaker stats), the global stats, and any frozen state — equivalent to kaldi's OnlineCmvn::GetState(cur_frame).
|
inline |
Number of frames accepted so far.
|
static |
Smooth window stats with speaker and global stats.
A port of kaldi's static OnlineCmvn::SmoothOnlineCmvnStats. Adds up to speaker_frames worth of speaker stats and up to global_frames worth of global stats to stats, scaled by their counts, so the total count approaches cmn_window (a no-op once it is reached).
| speaker_stats | [in] Speaker stats [2, dim+1], may be empty. |
| global_stats | [in] Global stats [2, dim+1] (required at runtime). |
| opts | [in] The options in use. |
| stats | [in,out] Window stats to smooth. |