Class cv::dnn::LSTMLayer#
LSTM recurrent layer.
#include <opencv2/dnn/all_layers.hpp>Collaboration diagram for cv::dnn::LSTMLayer:
Public Member Functions#
Public Member Functions inherited from cv::dnn::Layer
Return |
Name |
Description |
|---|---|---|
Initializes only name, type and blobs fields. |
||
|
||
|
||
|
||
|
||
|
|
Computes and sets internal parameters according to inputs, outputs and blobs. |
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
|
|
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. |
|
|
Computes and sets internal parameters according to inputs, outputs and blobs. |
|
|
Given the input blobs, computes the output blobs. |
|
|
Given the input blobs, computes the output blobs. |
|
Given the input blobs, computes the output blobs. |
|
|
||
|
||
|
||
|
Returns parameters of layers with channel-wise multiplication and addition. |
|
|
Returns scale and zeropoint of layers. |
|
|
||
|
Returns a CANN backend node. |
|
|
Returns a CUDA backend node. |
|
|
||
|
Returns a TimVX backend node. |
|
|
||
|
||
|
Returns index of input blob into the input array. |
|
|
||
|
Returns index of output blob in output array. |
|
|
Allocates layer and computes output. |
|
|
Tries to attach to the layer the subsequent activation layer, i.e. do the layer fusion in a partial case. |
|
|
Initializes only name, type and blobs fields. |
|
|
Ask layer if it support specific backend for doing computations. |
|
|
Try to fuse current layer with a next one. |
|
|
“Detaches” all the layers, attached to particular layer. |
|
|
Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Clears the algorithm state. |
|
|
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. |
|
|
Reads algorithm parameters from a file storage. |
|
|
||
|
|
|
|
Stores algorithm parameters in a file storage. |
|
|
Static Public Member Functions#
Static Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
|
Loads algorithm from the file. |
|
|
Loads algorithm from a String. |
|
Reads algorithm from the file node. |
Public Attributes#
Public Attributes inherited from cv::dnn::Layer
Return |
Name |
Description |
|---|---|---|
|
List of learned parameters must be stored here to allow read them by using Net::getParam(). |
|
|
||
Name of the layer instance, can be used for logging or other internal purposes. |
||
|
||
|
||
|
prefer target for layer forwarding |
|
Type name which was used for creating layer by layer factory. |
Additional Inherited Members#
Protected Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Detailed Description#
LSTM recurrent layer.
Member Function Documentation#
create()#
static Ptr< LSTMLayer > cv::dnn::LSTMLayer::create(const LayerParams & params)
Creates instance of LSTM layer
inputNameToIndex()#
int cv::dnn::LSTMLayer::inputNameToIndex(String inputName)
Returns index of input blob into the input array.
Each layer input and output can be labeled to easily identify them using “%<layer_name%>[.output_name]” notation. This method maps label of input blob to its index into input vector.
Parameters
inputName— label of input blob
outputNameToIndex()#
int cv::dnn::LSTMLayer::outputNameToIndex(const String & outputName)
Returns index of output blob in output array.
See also
setOutShape()#
void cv::dnn::LSTMLayer::setOutShape(const MatShape & outTailShape = MatShape())
Specifies shape of output blob which will be [[T], N] + outTailShape.
If this parameter is empty or unset then outTailShape = [Wh.size(0)] will be used, where Wh is parameter from setWeights().
setProduceCellOutput()#
void cv::dnn::LSTMLayer::setProduceCellOutput(bool produce = false)
If this flag is set to true then layer will produce \( c_t \) as second output.
Deprecated
Use flag use_timestamp_dim in LayerParams.
Shape of the second output is the same as first output.
setUseTimstampsDim()#
void cv::dnn::LSTMLayer::setUseTimstampsDim(bool use = true)
Specifies either interpret first dimension of input blob as timestamp dimension either as sample.
Deprecated
Use flag produce_cell_output in LayerParams.
If flag is set to true then shape of input blob will be interpreted as [T, N, [data dims]] where T specifies number of timestamps, N is number of independent streams. In this case each forward() call will iterate through T timestamps and update layer’s state T times.
If flag is set to false then shape of input blob will be interpreted as [N, [data dims]]. In this case each forward() call will make one iteration and produce one timestamp with shape [N, [out dims]].
setWeights()#
void cv::dnn::LSTMLayer::setWeights(
const Mat & Wh,
const Mat & Wx,
const Mat & b )
Set trained weights for LSTM layer.
Deprecated
Use LayerParams::blobs instead.
LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights.
Let \(x_t\) be current input, \(h_t\) be current output, \(c_t\) be current state. Than current output and current cell state is computed as follows: \begin{eqnarray*} h_t &= o_t \odot tanh(c_t), \ c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \ \end{eqnarray*} where \(\odot\) is per-element multiply operation and \(i_t, f_t, o_t, g_t\) is internal gates that are computed using learned weights.
Gates are computed as follows: \begin{eqnarray*} i_t &= sigmoid&(W_{xi} x_t + W_{hi} h_{t-1} + b_i), \ f_t &= sigmoid&(W_{xf} x_t + W_{hf} h_{t-1} + b_f), \ o_t &= sigmoid&(W_{xo} x_t + W_{ho} h_{t-1} + b_o), \ g_t &= tanh &(W_{xg} x_t + W_{hg} h_{t-1} + b_g), \ \end{eqnarray*} where \(W_{x?}\), \(W_{h?}\) and \(b_{?}\) are learned weights represented as matrices: \(W_{x?} \in R^{N_h \times N_x}\), \(W_{h?} \in R^{N_h \times N_h}\), \(b_? \in R^{N_h}\).
For simplicity and performance purposes we use \( W_x = [W_{xi}; W_{xf}; W_{xo}, W_{xg}] \) (i.e. \(W_x\) is vertical concatenation of \( W_{x?} \)), \( W_x \in R^{4N_h \times N_x} \). The same for \( W_h = [W_{hi}; W_{hf}; W_{ho}, W_{hg}], W_h \in R^{4N_h \times N_h} \) and for \( b = [b_i; b_f, b_o, b_g]\), \(b \in R^{4N_h} \).
Parameters
Wh— is matrix defining how previous output is transformed to internal gates (i.e. according to above mentioned notation is \( W_h \))Wx— is matrix defining how current input is transformed to internal gates (i.e. according to above mentioned notation is \( W_x \))b— is bias vector (i.e. according to above mentioned notation is \( b \))
Source file#
The documentation for this class was generated from the following file:
opencv2/dnn/all_layers.hpp