NnetComputerFromEg Class Reference
Collaboration diagram for NnetComputerFromEg:

Public Member Functions

 NnetComputerFromEg (const Nnet &nnet)
 
void Compute (const NnetExample &eg, const std::string &output_name, Matrix< BaseFloat > *output)
 
 NnetComputerFromEg (const Nnet &nnet)
 
void Compute (const NnetExample &eg, Matrix< BaseFloat > *output)
 

Private Attributes

const Nnetnnet_
 
CachingOptimizingCompiler compiler_
 

Detailed Description

Definition at line 32 of file nnet3-compute-from-egs.cc.

Constructor & Destructor Documentation

◆ NnetComputerFromEg() [1/2]

NnetComputerFromEg ( const Nnet nnet)
inline

Definition at line 34 of file nnet3-compute-from-egs.cc.

Referenced by main().

34  :
35  nnet_(nnet), compiler_(nnet) { }

◆ NnetComputerFromEg() [2/2]

NnetComputerFromEg ( const Nnet nnet)
inline

Definition at line 34 of file nnet3-discriminative-compute-from-egs.cc.

34  :
35  nnet_(nnet), compiler_(nnet) { }

Member Function Documentation

◆ Compute() [1/2]

void Compute ( const NnetExample eg,
Matrix< BaseFloat > *  output 
)
inline

Definition at line 39 of file nnet3-discriminative-compute-from-egs.cc.

References NnetComputer::AcceptInputs(), CachingOptimizingCompiler::Compile(), NnetComputerFromEg::compiler_, CuMatrixBase< Real >::CopyToMat(), NnetComputeOptions::debug, kaldi::nnet3::GetComputationRequest(), kaldi::GetVerboseLevel(), NnetExample::io, NnetComputerFromEg::nnet_, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().

39  {
40  ComputationRequest request;
41  bool need_backprop = false, store_stats = false;
42  GetComputationRequest(nnet_, eg, need_backprop, store_stats, &request);
43  const NnetComputation &computation = *(compiler_.Compile(request));
44  NnetComputeOptions options;
45  if (GetVerboseLevel() >= 3)
46  options.debug = true;
47  NnetComputer computer(options, computation, nnet_, NULL);
48  computer.AcceptInputs(nnet_, eg.io);
49  computer.Run();
50  const CuMatrixBase<BaseFloat> &nnet_output = computer.GetOutput("output");
51  output->Resize(nnet_output.NumRows(), nnet_output.NumCols());
52  nnet_output.CopyToMat(output);
53  }
void CopyToMat(MatrixBase< OtherReal > *dst, MatrixTransposeType trans=kNoTrans) const
Definition: cu-matrix.cc:447
int32 GetVerboseLevel()
Get verbosity level, usually set via command line &#39;–verbose=&#39; switch.
Definition: kaldi-error.h:60
void AcceptInputs(const Nnet &nnet, const std::vector< NnetIo > &io)
This convenience function calls AcceptInput() in turn on all the inputs in the training example...
std::shared_ptr< const NnetComputation > Compile(const ComputationRequest &request)
Does the compilation and returns a const pointer to the result, which is owned by this class...
Matrix for CUDA computing.
Definition: matrix-common.h:69
MatrixIndexT NumCols() const
Definition: cu-matrix.h:216
class NnetComputer is responsible for executing the computation described in the "computation" object...
Definition: nnet-compute.h:59
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).
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:215
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116
void GetComputationRequest(const Nnet &nnet, const NnetExample &eg, bool need_model_derivative, bool store_component_stats, ComputationRequest *request)
This function takes a NnetExample (which should already have been frame-selected, if desired...

◆ Compute() [2/2]

void Compute ( const NnetExample eg,
const std::string &  output_name,
Matrix< BaseFloat > *  output 
)
inline

Definition at line 41 of file nnet3-compute-from-egs.cc.

References NnetComputer::AcceptInputs(), CachingOptimizingCompiler::Compile(), NnetComputerFromEg::compiler_, CuMatrixBase< Real >::CopyToMat(), NnetComputeOptions::debug, kaldi::nnet3::GetComputationRequest(), kaldi::GetVerboseLevel(), NnetExample::io, NnetComputerFromEg::nnet_, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().

Referenced by main().

42  {
43  ComputationRequest request;
44  bool need_backprop = false, store_stats = false;
45  GetComputationRequest(nnet_, eg, need_backprop, store_stats, &request);
46  const NnetComputation &computation = *(compiler_.Compile(request));
47  NnetComputeOptions options;
48  if (GetVerboseLevel() >= 3)
49  options.debug = true;
50  NnetComputer computer(options, computation, nnet_, NULL);
51  computer.AcceptInputs(nnet_, eg.io);
52  computer.Run();
53  const CuMatrixBase<BaseFloat> &nnet_output = computer.GetOutput(output_name);
54  output->Resize(nnet_output.NumRows(), nnet_output.NumCols());
55  nnet_output.CopyToMat(output);
56  }
void CopyToMat(MatrixBase< OtherReal > *dst, MatrixTransposeType trans=kNoTrans) const
Definition: cu-matrix.cc:447
int32 GetVerboseLevel()
Get verbosity level, usually set via command line &#39;–verbose=&#39; switch.
Definition: kaldi-error.h:60
void AcceptInputs(const Nnet &nnet, const std::vector< NnetIo > &io)
This convenience function calls AcceptInput() in turn on all the inputs in the training example...
std::shared_ptr< const NnetComputation > Compile(const ComputationRequest &request)
Does the compilation and returns a const pointer to the result, which is owned by this class...
Matrix for CUDA computing.
Definition: matrix-common.h:69
MatrixIndexT NumCols() const
Definition: cu-matrix.h:216
class NnetComputer is responsible for executing the computation described in the "computation" object...
Definition: nnet-compute.h:59
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).
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:215
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116
void GetComputationRequest(const Nnet &nnet, const NnetExample &eg, bool need_model_derivative, bool store_component_stats, ComputationRequest *request)
This function takes a NnetExample (which should already have been frame-selected, if desired...

Member Data Documentation

◆ compiler_

CachingOptimizingCompiler compiler_
private

Definition at line 59 of file nnet3-compute-from-egs.cc.

Referenced by NnetComputerFromEg::Compute().

◆ nnet_

const Nnet & nnet_
private

Definition at line 58 of file nnet3-compute-from-egs.cc.

Referenced by NnetComputerFromEg::Compute().


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