OnlineFeatureMatrix Class Reference

#include <online-feat-input.h>

Collaboration diagram for OnlineFeatureMatrix:

Public Member Functions

 OnlineFeatureMatrix (const OnlineFeatureMatrixOptions &opts, OnlineFeatInputItf *input)
 
bool IsValidFrame (int32 frame)
 
int32 Dim () const
 
SubVector< BaseFloatGetFrame (int32 frame)
 

Private Member Functions

void GetNextFeatures ()
 

Private Attributes

const OnlineFeatureMatrixOptions opts_
 
OnlineFeatInputItfinput_
 
int32 feat_dim_
 
Matrix< BaseFloatfeat_matrix_
 
int32 feat_offset_
 
bool finished_
 

Detailed Description

Definition at line 370 of file online-feat-input.h.

Constructor & Destructor Documentation

◆ OnlineFeatureMatrix()

OnlineFeatureMatrix ( const OnlineFeatureMatrixOptions opts,
OnlineFeatInputItf input 
)
inline

Definition at line 372 of file online-feat-input.h.

373  :
374  opts_(opts), input_(input), feat_dim_(input->Dim()),
375  feat_offset_(0), finished_(false) { }
OnlineFeatInputItf * input_
const OnlineFeatureMatrixOptions opts_

Member Function Documentation

◆ Dim()

int32 Dim ( ) const
inline

Definition at line 379 of file online-feat-input.h.

379 { return feat_dim_; }

◆ GetFrame()

SubVector< BaseFloat > GetFrame ( int32  frame)

Definition at line 539 of file online-feat-input.cc.

References KALDI_ERR.

Referenced by OnlineDecodableDiagGmmScaled::CacheFrame(), and kaldi::TestOnlineFeatureMatrix().

539  {
540  if (frame < feat_offset_)
541  KALDI_ERR << "Attempting to get a discarded frame.";
542  if (frame >= feat_offset_ + feat_matrix_.NumRows())
543  KALDI_ERR << "Attempt get frame without check its validity.";
544  return feat_matrix_.Row(frame - feat_offset_);
545 }
Matrix< BaseFloat > feat_matrix_
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
#define KALDI_ERR
Definition: kaldi-error.h:147
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ GetNextFeatures()

void GetNextFeatures ( )
private

Definition at line 474 of file online-feat-input.cc.

References OnlineFeatInputItf::Compute(), OnlineDeltaInput::input_, KALDI_WARN, kaldi::kUndefined, MatrixBase< Real >::NumRows(), and OnlineDeltaInput::opts_.

474  {
475  if (finished_) return; // Nothing to do.
476 
477  // We always keep the most recent frame of features, if present,
478  // in case it is needed (this may happen when someone calls
479  // IsLastFrame(), which requires us to get the next frame, while
480  // they're still processing this frame.
481  bool have_last_frame = (feat_matrix_.NumRows() != 0);
482  Vector<BaseFloat> last_frame;
483  if (have_last_frame)
484  last_frame = feat_matrix_.Row(feat_matrix_.NumRows() - 1);
485 
486  int32 iter;
487  for (iter = 0; iter < opts_.num_tries; iter++) {
488  Matrix<BaseFloat> next_features(opts_.batch_size, feat_dim_);
489  finished_ = ! input_->Compute(&next_features);
490  if (next_features.NumRows() == 0 && ! finished_) {
491  // It timed out. Try again.
492  continue;
493  }
494  if (next_features.NumRows() > 0) {
495  int32 new_size = (have_last_frame ? 1 : 0) +
496  next_features.NumRows();
498  (have_last_frame ? 1 : 0); // we're discarding this many
499  // frames.
501  if (have_last_frame) {
502  feat_matrix_.Row(0).CopyFromVec(last_frame);
503  feat_matrix_.Range(1, next_features.NumRows(), 0, feat_dim_).
504  CopyFromMat(next_features);
505  } else {
506  feat_matrix_.CopyFromMat(next_features);
507  }
508  }
509  break;
510  }
511  if (iter == opts_.num_tries) { // we fell off the loop
512  KALDI_WARN << "After " << opts_.num_tries << ", got no features, giving up.";
513  finished_ = true; // We set finished_ to true even though the stream
514  // doesn't say it's finished, because the delay is too much-- we gave up.
515  }
516 }
Matrix< BaseFloat > feat_matrix_
kaldi::int32 int32
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
OnlineFeatInputItf * input_
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Definition: kaldi-matrix.h:188
#define KALDI_WARN
Definition: kaldi-error.h:150
const OnlineFeatureMatrixOptions opts_
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.
Definition: kaldi-matrix.h:202
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
virtual bool Compute(Matrix< BaseFloat > *output)=0

◆ IsValidFrame()

bool IsValidFrame ( int32  frame)

Definition at line 519 of file online-feat-input.cc.

References KALDI_ASSERT, and KALDI_WARN.

Referenced by OnlineDecodableDiagGmmScaled::CacheFrame(), OnlineDecodableDiagGmmScaled::IsLastFrame(), OnlineDecodableDiagGmmScaled::OnlineDecodableDiagGmmScaled(), and kaldi::TestOnlineFeatureMatrix().

519  {
520  KALDI_ASSERT(frame >= feat_offset_ &&
521  "You are attempting to get expired frames.");
522  if (frame < feat_offset_ + feat_matrix_.NumRows())
523  return true;
524  else {
525  GetNextFeatures();
526  if (frame < feat_offset_ + feat_matrix_.NumRows())
527  return true;
528  else {
529  if (finished_) return false;
530  else {
531  KALDI_WARN << "Unexpected point reached in code: "
532  << "possibly you are skipping frames?";
533  return false;
534  }
535  }
536  }
537 }
Matrix< BaseFloat > feat_matrix_
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

Member Data Documentation

◆ feat_dim_

int32 feat_dim_
private

Definition at line 392 of file online-feat-input.h.

◆ feat_matrix_

Matrix<BaseFloat> feat_matrix_
private

Definition at line 393 of file online-feat-input.h.

◆ feat_offset_

int32 feat_offset_
private

Definition at line 394 of file online-feat-input.h.

◆ finished_

bool finished_
private

Definition at line 395 of file online-feat-input.h.

◆ input_

OnlineFeatInputItf* input_
private

Definition at line 391 of file online-feat-input.h.

◆ opts_

const OnlineFeatureMatrixOptions opts_
private

Definition at line 390 of file online-feat-input.h.


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