42 t_in_ != initial_t_in) {
46 output->
Resize(orig_nr, orig_nc);
58 bool more_data)
const {
84 int32 num_input_frames = input.NumRows();
88 output->
Resize(output_frames,
89 output_frames == 0 ? 0 :
Dim());
91 int32 output_counter = 0;
92 for (
int32 i = 0;
i < num_input_frames;
i++) {
102 for (; output_counter < output_frames; output_counter++) {
125 for (
int32 i = 0;
i < num_frames;
i++)
128 int32 num_history_frames;
133 num_history_frames =
t_out_;
137 output->
AddVec(-1.0 / num_history_frames,
sum_);
150 #if !defined(_MSC_VER) 153 feature_dim_(feature_dim) {
157 sock_desc_ = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
160 int32 rcvbuf_size = 30000;
161 if (setsockopt(
sock_desc_, SOL_SOCKET, SO_RCVBUF,
162 &rcvbuf_size,
sizeof(rcvbuf_size)) == -1)
163 KALDI_ERR <<
"setsockopt() failed to set receive buffer size!";
174 ssize_t nrecv = recvfrom(
sock_desc_, buf,
sizeof(buf), 0,
182 std::stringstream ss(std::stringstream::in | std::stringstream::out);
183 ss.write(buf, nrecv);
184 output->
Read(ss,
true);
194 int32 right_context):
195 input_(input), input_dim_(input->
Dim()),
196 left_context_(left_context), right_context_(right_context) {
198 int32 tot_context = left_context + 1 + right_context;
209 KALDI_ERR <<
"Invalid parameters supplied to OnlineLdaInput";
217 int32 context_window,
222 int32 num_frames_in = size1 + size2 + size3,
223 num_frames_out = num_frames_in - (context_window - 1),
227 if (num_frames_out <= 0) {
231 output->
Resize(num_frames_out, dim * context_window);
232 for (
int32 t_out = 0; t_out < num_frames_out; t_out++) {
233 for (
int32 pos = 0; pos < context_window; pos++) {
234 int32 t_in = t_out + pos;
238 else if (t_in < size1 + size2)
239 vec_out.CopyFromVec(input2.
Row(t_in - size1));
241 vec_out.CopyFromVec(input3.
Row(t_in - size1 - size2));
248 if (spliced_feats.
NumRows() == 0) {
271 if (input.NumRows() == 0 && ans) {
274 }
else if (input.NumRows() == 0 && !ans) {
296 if (input.NumRows() > 0)
297 tail.
Row(
i).CopyFromVec(input.Row(input.NumRows() - 1));
316 int32 next_remainder_len = std::min(context_window - 1,
318 if (next_remainder_len == 0) {
324 for (
int32 i = 0;
i < next_remainder_len;
i++) {
326 int32 t = (rsize + isize) - next_remainder_len +
i;
344 int32 num_frames = 0, dim = 0;
345 for (
size_t i = 0;
i <
data_.size();
i++) {
346 num_frames +=
data_[
i]->NumRows();
347 dim =
data_[
i]->NumCols();
349 output->
Resize(num_frames, dim);
350 int32 frame_offset = 0;
351 for (
size_t i = 0;
i <
data_.size();
i++) {
353 output->
Range(frame_offset, this_frames, 0, dim).CopyFromMat(*
data_[
i]);
354 frame_offset += this_frames;
376 size3 = input3.
NumRows(), size_out = size1 + size2 + size3;
385 output->
Resize(size_out, dim);
387 output->
Range(0, size1, 0, dim).CopyFromMat(input1);
389 output->
Range(size1, size2, 0, dim).CopyFromMat(input2);
391 output->
Range(size1 + size2, size3, 0, dim).CopyFromMat(input3);
398 output_rows = std::max(0, input_rows -
Context() * 2),
399 remainder_rows = std::min(input_rows,
Context() * 2),
402 if (remainder_rows > 0) {
403 remainder->
Resize(remainder_rows, input_dim);
405 remainder_rows, 0, input_dim));
409 if (output_rows > 0) {
410 output->
Resize(output_rows, output_dim);
412 for (
int32 output_frame = 0; output_frame < output_rows; output_frame++) {
415 delta.
Process(input, input_frame, &output_row);
434 if (input.NumRows() == 0 && ans) {
437 }
else if (input.NumRows() == 0 && !ans) {
459 if (input.NumRows() > 0)
460 tail.
Row(
i).CopyFromVec(input.Row(input.NumRows() - 1));
475 if (finished_)
return;
481 bool have_last_frame = (feat_matrix_.NumRows() != 0);
484 last_frame = feat_matrix_.Row(feat_matrix_.NumRows() - 1);
487 for (iter = 0; iter <
opts_.num_tries; iter++) {
490 if (next_features.
NumRows() == 0 && ! finished_) {
494 if (next_features.
NumRows() > 0) {
495 int32 new_size = (have_last_frame ? 1 : 0) +
497 feat_offset_ += feat_matrix_.NumRows() -
498 (have_last_frame ? 1 : 0);
500 feat_matrix_.Resize(new_size, feat_dim_,
kUndefined);
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);
506 feat_matrix_.CopyFromMat(next_features);
511 if (iter ==
opts_.num_tries) {
512 KALDI_WARN <<
"After " <<
opts_.num_tries <<
", got no features, giving up.";
521 "You are attempting to get expired frames.");
522 if (frame < feat_offset_ + feat_matrix_.NumRows())
526 if (frame < feat_offset_ + feat_matrix_.NumRows())
529 if (finished_)
return false;
531 KALDI_WARN <<
"Unexpected point reached in code: " 532 <<
"possibly you are skipping frames?";
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_);
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Base class which provides matrix operations not involving resizing or allocation. ...
void Swap(Matrix< Real > *other)
Swaps the contents of *this and *other. Shallow swap.
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
void Read(std::istream &in, bool binary, bool add=false)
read from stream.
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void AddVecToRows(const Real alpha, const VectorBase< OtherReal > &v)
[each row of *this] += alpha * v
void Process(const MatrixBase< BaseFloat > &input_feats, int32 frame, VectorBase< BaseFloat > *output_frame) const
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
A class representing a vector.
SubVector< BaseFloat > GetFrame(int32 frame)
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
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.
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).
Provides a vector abstraction class.
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
bool IsValidFrame(int32 frame)