OnlineDeltaFeature Class Reference

#include <online-feature.h>

Inheritance diagram for OnlineDeltaFeature:
Collaboration diagram for OnlineDeltaFeature:

Public Member Functions

virtual int32 Dim () const
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
virtual BaseFloat FrameShiftInSeconds () const
 
virtual int32 NumFramesReady () const
 returns the feature dimension. More...
 
virtual void GetFrame (int32 frame, VectorBase< BaseFloat > *feat)
 Gets the feature vector for this frame. More...
 
 OnlineDeltaFeature (const DeltaFeaturesOptions &opts, OnlineFeatureInterface *src)
 
- 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 Attributes

OnlineFeatureInterfacesrc_
 
DeltaFeaturesOptions opts_
 
DeltaFeatures delta_features_
 

Detailed Description

Definition at line 530 of file online-feature.h.

Constructor & Destructor Documentation

◆ OnlineDeltaFeature()

Definition at line 600 of file online-feature.cc.

601  :
602  src_(src), opts_(opts), delta_features_(opts) { }
DeltaFeaturesOptions opts_
OnlineFeatureInterface * src_

Member Function Documentation

◆ Dim()

int32 Dim ( ) const
virtual

Implements OnlineFeatureInterface.

Definition at line 557 of file online-feature.cc.

References OnlineFeatureInterface::Dim(), and OnlineTransform::src_.

Referenced by OnlineCacheFeature::GetFrame(), OnlineAppendFeature::GetFrame(), and OnlineCacheFeature::GetFrames().

557  {
558  int32 src_dim = src_->Dim();
559  return src_dim * (1 + opts_.order);
560 }
DeltaFeaturesOptions opts_
kaldi::int32 int32
virtual int32 Dim() const =0
OnlineFeatureInterface * src_

◆ FrameShiftInSeconds()

virtual BaseFloat FrameShiftInSeconds ( ) const
inlinevirtual

Implements OnlineFeatureInterface.

Definition at line 540 of file online-feature.h.

540  {
541  return src_->FrameShiftInSeconds();
542  }
virtual BaseFloat FrameShiftInSeconds() const =0
OnlineFeatureInterface * src_

◆ GetFrame()

void GetFrame ( int32  frame,
VectorBase< BaseFloat > *  feat 
)
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 573 of file online-feature.cc.

References OnlineFeatureInterface::Dim(), VectorBase< Real >::Dim(), OnlineTransform::Dim(), OnlineFeatureInterface::GetFrame(), KALDI_ASSERT, OnlineFeatureInterface::NumFramesReady(), OnlineTransform::NumFramesReady(), and OnlineTransform::src_.

574  {
575  KALDI_ASSERT(frame >= 0 && frame < NumFramesReady());
576  KALDI_ASSERT(feat->Dim() == Dim());
577  // We'll produce a temporary matrix containing the features we want to
578  // compute deltas on, but truncated to the necessary context.
579  int32 context = opts_.order * opts_.window;
580  int32 left_frame = frame - context,
581  right_frame = frame + context,
582  src_frames_ready = src_->NumFramesReady();
583  if (left_frame < 0) left_frame = 0;
584  if (right_frame >= src_frames_ready)
585  right_frame = src_frames_ready - 1;
586  KALDI_ASSERT(right_frame >= left_frame);
587  int32 temp_num_frames = right_frame + 1 - left_frame,
588  src_dim = src_->Dim();
589  Matrix<BaseFloat> temp_src(temp_num_frames, src_dim);
590  for (int32 t = left_frame; t <= right_frame; t++) {
591  SubVector<BaseFloat> temp_row(temp_src, t - left_frame);
592  src_->GetFrame(t, &temp_row);
593  }
594  int32 temp_t = frame - left_frame; // temp_t is the offset of frame "frame"
595  // within temp_src
596  delta_features_.Process(temp_src, temp_t, feat);
597 }
DeltaFeaturesOptions opts_
virtual void GetFrame(int32 frame, VectorBase< BaseFloat > *feat)=0
Gets the feature vector for this frame.
kaldi::int32 int32
void Process(const MatrixBase< BaseFloat > &input_feats, int32 frame, VectorBase< BaseFloat > *output_frame) const
virtual int32 NumFramesReady() const
returns the feature dimension.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual int32 Dim() const
virtual int32 NumFramesReady() const =0
returns the feature dimension.
virtual int32 Dim() const =0
OnlineFeatureInterface * src_

◆ IsLastFrame()

virtual bool IsLastFrame ( int32  frame) const
inlinevirtual

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 537 of file online-feature.h.

537  {
538  return src_->IsLastFrame(frame);
539  }
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.
OnlineFeatureInterface * src_

◆ NumFramesReady()

int32 NumFramesReady ( ) const
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 562 of file online-feature.cc.

References OnlineFeatureInterface::IsLastFrame(), OnlineFeatureInterface::NumFramesReady(), and OnlineTransform::src_.

562  {
563  int32 num_frames = src_->NumFramesReady(),
564  context = opts_.order * opts_.window;
565  // "context" is the number of frames on the left or (more relevant
566  // here) right which we need in order to produce the output.
567  if (num_frames > 0 && src_->IsLastFrame(num_frames-1))
568  return num_frames;
569  else
570  return std::max<int32>(0, num_frames - context);
571 }
DeltaFeaturesOptions opts_
kaldi::int32 int32
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.
virtual int32 NumFramesReady() const =0
returns the feature dimension.
OnlineFeatureInterface * src_

Member Data Documentation

◆ delta_features_

DeltaFeatures delta_features_
private

Definition at line 557 of file online-feature.h.

◆ opts_

DeltaFeaturesOptions opts_
private

Definition at line 556 of file online-feature.h.

◆ src_

OnlineFeatureInterface* src_
private

The documentation for this class was generated from the following files: