pub struct GRULayer { /* private fields */ }Expand description
GRU recurrent one-layer
Accepts input sequence and computes the final hidden state for each element in the batch.
- input[0] containing the features of the input sequence.
input[0] should have shape [
T,N,data_dims] whereTis sequence length,Nis batch size,data_dimsis input size - output would have shape [
T,N,D*hidden_size] whereD = 2if layer is bidirectional otherwiseD = 1
Depends on the following attributes:
- hidden_size - Number of neurons in the hidden layer
- direction - RNN could be bidirectional or forward
The final hidden state @f$ h_t @f$ computes by the following formulas:
@f{eqnarray*}{ r_t = \sigma(W_{ir} x_t + b_{ir} + W_{hr} h_{(t-1)} + b_{hr}) \ z_t = \sigma(W_{iz} x_t + b_{iz} + W_{hz} h_{(t-1)} + b_{hz}) \ n_t = \tanh(W_{in} x_t + b_{in} + r_t \odot (W_{hn} h_{(t-1)}+ b_{hn})) \ h_t = (1 - z_t) \odot n_t + z_t \odot h_{(t-1)} \ @f} Where @f$x_t@f$ is current input, @f$h_{(t-1)}@f$ is previous or initial hidden state.
@f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices: @f$W_{x?} \in R^{N_h \times N_x}@f$, @f$W_{h?} \in R^{N_h \times N_h}@f$, @f$b_? \in R^{N_h}@f$.
@f$\odot@f$ is per-element multiply operation.
Implementations§
Trait Implementations§
source§impl AlgorithmTrait for GRULayer
impl AlgorithmTrait for GRULayer
source§impl AlgorithmTraitConst for GRULayer
impl AlgorithmTraitConst for GRULayer
fn as_raw_Algorithm(&self) -> *const c_void
source§fn write(&self, fs: &mut impl FileStorageTrait) -> Result<()>
fn write(&self, fs: &mut impl FileStorageTrait) -> Result<()>
source§fn write_1(&self, fs: &mut impl FileStorageTrait, name: &str) -> Result<()>
fn write_1(&self, fs: &mut impl FileStorageTrait, name: &str) -> Result<()>
source§fn write_with_name(&self, fs: &Ptr<FileStorage>, name: &str) -> Result<()>
fn write_with_name(&self, fs: &Ptr<FileStorage>, name: &str) -> Result<()>
source§fn write_with_name_def(&self, fs: &Ptr<FileStorage>) -> Result<()>
fn write_with_name_def(&self, fs: &Ptr<FileStorage>) -> Result<()>
§Note
source§fn empty(&self) -> Result<bool>
fn empty(&self) -> Result<bool>
source§fn save(&self, filename: &str) -> Result<()>
fn save(&self, filename: &str) -> Result<()>
source§fn get_default_name(&self) -> Result<String>
fn get_default_name(&self) -> Result<String>
source§impl Boxed for GRULayer
impl Boxed for GRULayer
source§unsafe fn from_raw(ptr: <GRULayer as OpenCVFromExtern>::ExternReceive) -> Self
unsafe fn from_raw(ptr: <GRULayer as OpenCVFromExtern>::ExternReceive) -> Self
source§fn into_raw(self) -> <GRULayer as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw(self) -> <GRULayer as OpenCVTypeExternContainer>::ExternSendMut
source§fn as_raw(&self) -> <GRULayer as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <GRULayer as OpenCVTypeExternContainer>::ExternSend
source§fn as_raw_mut(
&mut self,
) -> <GRULayer as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut( &mut self, ) -> <GRULayer as OpenCVTypeExternContainer>::ExternSendMut
source§impl GRULayerTrait for GRULayer
impl GRULayerTrait for GRULayer
fn as_raw_mut_GRULayer(&mut self) -> *mut c_void
source§impl GRULayerTraitConst for GRULayer
impl GRULayerTraitConst for GRULayer
fn as_raw_GRULayer(&self) -> *const c_void
source§impl LayerTrait for GRULayer
impl LayerTrait for GRULayer
fn as_raw_mut_Layer(&mut self) -> *mut c_void
source§fn set_blobs(&mut self, val: Vector<Mat>)
fn set_blobs(&mut self, val: Vector<Mat>)
source§fn set_name(&mut self, val: &str)
fn set_name(&mut self, val: &str)
source§fn set_type(&mut self, val: &str)
fn set_type(&mut self, val: &str)
source§fn set_preferable_target(&mut self, val: i32)
fn set_preferable_target(&mut self, val: i32)
source§fn finalize(
&mut self,
inputs: &impl ToInputArray,
outputs: &mut impl ToOutputArray,
) -> Result<()>
fn finalize( &mut self, inputs: &impl ToInputArray, outputs: &mut impl ToOutputArray, ) -> Result<()>
source§fn forward_mat(
&mut self,
input: &mut Vector<Mat>,
output: &mut Vector<Mat>,
internals: &mut Vector<Mat>,
) -> Result<()>
fn forward_mat( &mut self, input: &mut Vector<Mat>, output: &mut Vector<Mat>, internals: &mut Vector<Mat>, ) -> Result<()>
source§fn forward(
&mut self,
inputs: &impl ToInputArray,
outputs: &mut impl ToOutputArray,
internals: &mut impl ToOutputArray,
) -> Result<()>
fn forward( &mut self, inputs: &impl ToInputArray, outputs: &mut impl ToOutputArray, internals: &mut impl ToOutputArray, ) -> Result<()>
source§fn try_quantize(
&mut self,
scales: &Vector<Vector<f32>>,
zeropoints: &Vector<Vector<i32>>,
params: &mut impl LayerParamsTrait,
) -> Result<bool>
fn try_quantize( &mut self, scales: &Vector<Vector<f32>>, zeropoints: &Vector<Vector<i32>>, params: &mut impl LayerParamsTrait, ) -> Result<bool>
source§fn forward_fallback(
&mut self,
inputs: &impl ToInputArray,
outputs: &mut impl ToOutputArray,
internals: &mut impl ToOutputArray,
) -> Result<()>
fn forward_fallback( &mut self, inputs: &impl ToInputArray, outputs: &mut impl ToOutputArray, internals: &mut impl ToOutputArray, ) -> Result<()>
source§fn finalize_mat_to(
&mut self,
inputs: &Vector<Mat>,
outputs: &mut Vector<Mat>,
) -> Result<()>
fn finalize_mat_to( &mut self, inputs: &Vector<Mat>, outputs: &mut Vector<Mat>, ) -> Result<()>
source§fn finalize_mat(&mut self, inputs: &Vector<Mat>) -> Result<Vector<Mat>>
fn finalize_mat(&mut self, inputs: &Vector<Mat>) -> Result<Vector<Mat>>
source§fn run(
&mut self,
inputs: &Vector<Mat>,
outputs: &mut Vector<Mat>,
internals: &mut Vector<Mat>,
) -> Result<()>
fn run( &mut self, inputs: &Vector<Mat>, outputs: &mut Vector<Mat>, internals: &mut Vector<Mat>, ) -> Result<()>
source§fn input_name_to_index(&mut self, input_name: &str) -> Result<i32>
fn input_name_to_index(&mut self, input_name: &str) -> Result<i32>
source§fn output_name_to_index(&mut self, output_name: &str) -> Result<i32>
fn output_name_to_index(&mut self, output_name: &str) -> Result<i32>
source§fn support_backend(&mut self, backend_id: i32) -> Result<bool>
fn support_backend(&mut self, backend_id: i32) -> Result<bool>
source§fn init_halide(
&mut self,
inputs: &Vector<Ptr<BackendWrapper>>,
) -> Result<Ptr<BackendNode>>
fn init_halide( &mut self, inputs: &Vector<Ptr<BackendWrapper>>, ) -> Result<Ptr<BackendNode>>
fn init_ngraph( &mut self, inputs: &Vector<Ptr<BackendWrapper>>, nodes: &Vector<Ptr<BackendNode>>, ) -> Result<Ptr<BackendNode>>
fn init_vk_com( &mut self, inputs: &Vector<Ptr<BackendWrapper>>, outputs: &mut Vector<Ptr<BackendWrapper>>, ) -> Result<Ptr<BackendNode>>
fn init_webnn( &mut self, inputs: &Vector<Ptr<BackendWrapper>>, nodes: &Vector<Ptr<BackendNode>>, ) -> Result<Ptr<BackendNode>>
source§unsafe fn init_cuda(
&mut self,
context: *mut c_void,
inputs: &Vector<Ptr<BackendWrapper>>,
outputs: &Vector<Ptr<BackendWrapper>>,
) -> Result<Ptr<BackendNode>>
unsafe fn init_cuda( &mut self, context: *mut c_void, inputs: &Vector<Ptr<BackendWrapper>>, outputs: &Vector<Ptr<BackendWrapper>>, ) -> Result<Ptr<BackendNode>>
source§unsafe fn init_tim_vx(
&mut self,
tim_vx_info: *mut c_void,
inputs_wrapper: &Vector<Ptr<BackendWrapper>>,
outputs_wrapper: &Vector<Ptr<BackendWrapper>>,
is_last: bool,
) -> Result<Ptr<BackendNode>>
unsafe fn init_tim_vx( &mut self, tim_vx_info: *mut c_void, inputs_wrapper: &Vector<Ptr<BackendWrapper>>, outputs_wrapper: &Vector<Ptr<BackendWrapper>>, is_last: bool, ) -> Result<Ptr<BackendNode>>
source§fn init_cann(
&mut self,
inputs: &Vector<Ptr<BackendWrapper>>,
outputs: &Vector<Ptr<BackendWrapper>>,
nodes: &Vector<Ptr<BackendNode>>,
) -> Result<Ptr<BackendNode>>
fn init_cann( &mut self, inputs: &Vector<Ptr<BackendWrapper>>, outputs: &Vector<Ptr<BackendWrapper>>, nodes: &Vector<Ptr<BackendNode>>, ) -> Result<Ptr<BackendNode>>
source§fn try_attach(&mut self, node: &Ptr<BackendNode>) -> Result<Ptr<BackendNode>>
fn try_attach(&mut self, node: &Ptr<BackendNode>) -> Result<Ptr<BackendNode>>
source§fn set_activation(&mut self, layer: &Ptr<ActivationLayer>) -> Result<bool>
fn set_activation(&mut self, layer: &Ptr<ActivationLayer>) -> Result<bool>
source§fn try_fuse(&mut self, top: &mut Ptr<Layer>) -> Result<bool>
fn try_fuse(&mut self, top: &mut Ptr<Layer>) -> Result<bool>
source§fn unset_attached(&mut self) -> Result<()>
fn unset_attached(&mut self) -> Result<()>
fn update_memory_shapes(&mut self, inputs: &Vector<MatShape>) -> Result<bool>
fn set_params_from(&mut self, params: &impl LayerParamsTraitConst) -> Result<()>
source§impl LayerTraitConst for GRULayer
impl LayerTraitConst for GRULayer
fn as_raw_Layer(&self) -> *const c_void
source§fn blobs(&self) -> Vector<Mat>
fn blobs(&self) -> Vector<Mat>
source§fn name(&self) -> String
fn name(&self) -> String
source§fn preferable_target(&self) -> i32
fn preferable_target(&self) -> i32
source§fn apply_halide_scheduler(
&self,
node: &mut Ptr<BackendNode>,
inputs: &Vector<Mat>,
outputs: &Vector<Mat>,
target_id: i32,
) -> Result<()>
fn apply_halide_scheduler( &self, node: &mut Ptr<BackendNode>, inputs: &Vector<Mat>, outputs: &Vector<Mat>, target_id: i32, ) -> Result<()>
source§fn get_scale_shift(
&self,
scale: &mut impl MatTrait,
shift: &mut impl MatTrait,
) -> Result<()>
fn get_scale_shift( &self, scale: &mut impl MatTrait, shift: &mut impl MatTrait, ) -> Result<()>
source§fn get_scale_zeropoint(
&self,
scale: &mut f32,
zeropoint: &mut i32,
) -> Result<()>
fn get_scale_zeropoint( &self, scale: &mut f32, zeropoint: &mut i32, ) -> Result<()>
fn get_memory_shapes( &self, inputs: &Vector<MatShape>, required_outputs: i32, outputs: &mut Vector<MatShape>, internals: &mut Vector<MatShape>, ) -> Result<bool>
fn get_flops( &self, inputs: &Vector<MatShape>, outputs: &Vector<MatShape>, ) -> Result<i64>
impl Send for GRULayer
Auto Trait Implementations§
impl Freeze for GRULayer
impl RefUnwindSafe for GRULayer
impl !Sync for GRULayer
impl Unpin for GRULayer
impl UnwindSafe for GRULayer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res,
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res
Mat or another similar object. By passing
a mutable reference to the Mat to this function your closure will get called with the read reference and a write references
to the same Mat. This is unsafe in a general case as it leads to having non-exclusive mutable access to the internal data,
but it can be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place
modification is imgproc::threshold. Read more