@Namespace(value="cv::dnn") @Properties(inherit=opencv_dnn.class) public class LSTMLayer extends Layer
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
LSTMLayer(Pointer p)
Pointer cast constructor.
|
Modifier and Type | Method and Description |
---|---|
static LSTMLayer |
create(LayerParams params)
Creates instance of LSTM layer
|
int |
inputNameToIndex(BytePointer inputName)
\brief Returns index of input blob into the input array.
|
int |
inputNameToIndex(String inputName) |
int |
outputNameToIndex(BytePointer outputName)
\brief Returns index of output blob in output array.
|
int |
outputNameToIndex(String outputName) |
void |
setOutShape() |
void |
setOutShape(IntPointer outTailShape)
\brief Specifies shape of output blob which will be [[
T ], N ] + \p outTailShape. |
void |
setProduceCellOutput()
Deprecated.
|
void |
setProduceCellOutput(boolean produce)
Deprecated.
Use flag
use_timestamp_dim in LayerParams.
\brief If this flag is set to true then layer will produce c_t as second output.
\details Shape of the second output is the same as first output. |
void |
setUseTimstampsDim()
Deprecated.
|
void |
setUseTimstampsDim(boolean use)
Deprecated.
Use flag
produce_cell_output in LayerParams.
\brief Specifies either interpret first dimension of input blob as timestamp dimension either as sample.
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] ]. |
void |
setWeights(Mat Wh,
Mat Wx,
Mat b)
Deprecated.
Use LayerParams::blobs instead.
\brief Set trained weights for LSTM layer.
LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights.
Let
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:
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 |
applyHalideScheduler, blobs, blobs, finalize, finalize, finalize, finalize, finalize, forward_fallback, forward_fallback, forward_fallback, forward, forward, forward, forward, getFLOPS, getMemoryShapes, getScaleShift, name, name, position, preferableTarget, preferableTarget, run, setActivation, setParamsFrom, supportBackend, tryAttach, tryFuse, type, type, unsetAttached
clear, empty, getDefaultName, read, save, save, write, write, write
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, hashCode, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, parseBytes, physicalBytes, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, toString, totalBytes, totalPhysicalBytes, withDeallocator, zero
public LSTMLayer(Pointer p)
Pointer.Pointer(Pointer)
.@opencv_core.Ptr public static LSTMLayer create(@Const @ByRef LayerParams params)
@Deprecated public void setWeights(@Const @ByRef Mat Wh, @Const @ByRef Mat Wx, @Const @ByRef Mat b)
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}
.
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
)public void setOutShape(@Const @StdVector @ByRef(nullValue="cv::dnn::MatShape()") IntPointer outTailShape)
T
], N
] + \p outTailShape.
\details If this parameter is empty or unset then \p outTailShape = [Wh
.size(0)] will be used,
where Wh
is parameter from setWeights().public void setOutShape()
@Deprecated public void setUseTimstampsDim(@Cast(value="bool") boolean use)
produce_cell_output
in LayerParams.
\brief Specifies either interpret first dimension of input blob as timestamp dimension either as sample.
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]
].@Deprecated public void setUseTimstampsDim()
@Deprecated public void setProduceCellOutput(@Cast(value="bool") boolean produce)
use_timestamp_dim
in LayerParams.
\brief If this flag is set to true then layer will produce c_t
as second output.
\details Shape of the second output is the same as first output.@Deprecated public void setProduceCellOutput()
public int inputNameToIndex(@opencv_core.Str BytePointer inputName)
Layer
inputNameToIndex
in class Layer
inputName
- label of input blob
Each layer input and output can be labeled to easily identify them using "%public int inputNameToIndex(@opencv_core.Str String inputName)
inputNameToIndex
in class Layer
public int outputNameToIndex(@opencv_core.Str BytePointer outputName)
Layer
outputNameToIndex
in class Layer
inputNameToIndex()
public int outputNameToIndex(@opencv_core.Str String outputName)
outputNameToIndex
in class Layer
Copyright © 2020. All rights reserved.