OpenCV 4.12.0
开源计算机视觉
加载中...
搜索中...
无匹配项

经典的循环层。 更多...

#include <opencv2/dnn/all_layers.hpp>

cv::dnn::RNNLayer 协作图

公共成员函数

virtual void setProduceHiddenOutput (bool produce=false)=0
 如果此标志设置为 true,则层将生成 \( h_t \) 作为第二个输出。
 
virtual void setWeights (const Mat &Wxh, const Mat &bh, const Mat &Whh, const Mat &Who, const Mat &bo)=0
 
- 继承自 cv::dnn::Layer 的公共成员函数
 Layer ()
 
 Layer (const LayerParams &params)
 仅初始化 nametypeblobs 字段。
 
virtual ~Layer ()
 
virtual void applyHalideScheduler (Ptr< BackendNode > &node, const std::vector< Mat * > &inputs, const std::vector< Mat > &outputs, int targetId) const
 基于层超参数的 Halide 自动调度。
 
virtual void finalize (const std::vector< Mat * > &input, std::vector< Mat > &output)
 根据输入、输出和 blob 计算并设置内部参数。
 
std::vector< Matfinalize (const std::vector< Mat > &inputs)
 这是为方便起见而提供的重载成员函数。它与上述函数的区别仅在于接受的参数。
 
void finalize (const std::vector< Mat > &inputs, std::vector< Mat > &outputs)
 这是为方便起见而提供的重载成员函数。它与上述函数的区别仅在于接受的参数。
 
virtual void finalize (InputArrayOfArrays inputs, OutputArrayOfArrays outputs)
 根据输入、输出和 blob 计算并设置内部参数。
 
virtual void forward (InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals)
 给定 input blob,计算输出 blobs
 
virtual void forward (std::vector< Mat * > &input, std::vector< Mat > &output, std::vector< Mat > &internals)
 给定 input blob,计算输出 blobs
 
void forward_fallback (InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals)
 给定 input blob,计算输出 blobs
 
virtual int64 getFLOPS (const std::vector< MatShape > &inputs, const std::vector< MatShape > &outputs) const
 
virtual bool getMemoryShapes (const std::vector< MatShape > &inputs, const int requiredOutputs, std::vector< MatShape > &outputs, std::vector< MatShape > &internals) const
 
virtual void getScaleShift (Mat &scale, Mat &shift) const
 返回具有通道级乘法和加法操作的层的参数。
 
virtual void getScaleZeropoint (float &scale, int &zeropoint) const
 返回层的缩放和零点。
 
virtual Ptr< BackendNodeinitCann (const std::vector< Ptr< BackendWrapper > > &inputs, const std::vector< Ptr< BackendWrapper > > &outputs, const std::vector< Ptr< BackendNode > > &nodes)
 返回一个 CANN 后端节点。
 
virtual Ptr< BackendNodeinitCUDA (void *context, const std::vector< Ptr< BackendWrapper > > &inputs, const std::vector< Ptr< BackendWrapper > > &outputs)
 返回一个 CUDA 后端节点。
 
virtual Ptr< BackendNodeinitHalide (const std::vector< Ptr< BackendWrapper > > &inputs)
 返回 Halide 后端节点。
 
virtual Ptr< BackendNodeinitNgraph (const std::vector< Ptr< BackendWrapper > > &inputs, const std::vector< Ptr< BackendNode > > &nodes)
 
virtual Ptr< BackendNodeinitTimVX (void *timVxInfo, const std::vector< Ptr< BackendWrapper > > &inputsWrapper, const std::vector< Ptr< BackendWrapper > > &outputsWrapper, bool isLast)
 返回一个 TimVX 后端节点。
 
virtual Ptr< BackendNodeinitVkCom (const std::vector< Ptr< BackendWrapper > > &inputs, std::vector< Ptr< BackendWrapper > > &outputs)
 
virtual Ptr< BackendNodeinitWebnn (const std::vector< Ptr< BackendWrapper > > &inputs, const std::vector< Ptr< BackendNode > > &nodes)
 
virtual int inputNameToIndex (String inputName)
 返回输入 blob 在输入数组中的索引。
 
virtual int outputNameToIndex (const String &outputName)
 返回输出 blob 在输出数组中的索引。
 
void run (const std::vector< Mat > &inputs, std::vector< Mat > &outputs, std::vector< Mat > &internals)
 分配层并计算输出。
 
virtual bool setActivation (const Ptr< ActivationLayer > &layer)
 尝试将后续激活层附加到当前层,即在部分情况下执行层融合。
 
void setParamsFrom (const LayerParams &params)
 仅初始化 nametypeblobs 字段。
 
virtual bool supportBackend (int backendId)
 询问层是否支持特定的后端进行计算。
 
virtual Ptr< BackendNodetryAttach (const Ptr< BackendNode > &node)
 实现层融合。
 
virtual bool tryFuse (Ptr< Layer > &top)
 尝试将当前层与下一层融合。
 
virtual bool tryQuantize (const std::vector< std::vector< float > > &scales, const std::vector< std::vector< int > > &zeropoints, LayerParams &params)
 尝试量化给定层并计算定点实现所需的量化参数。
 
virtual void unsetAttached ()
 “分离”所有附加到特定层的层。
 
virtual bool updateMemoryShapes (const std::vector< MatShape > &inputs)
 
- 继承自 cv::Algorithm 的公共成员函数
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 清除算法状态。
 
virtual bool empty () const
 如果 Algorithm 为空(例如在最初或读取失败后),则返回 true。
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 从文件存储中读取算法参数。
 
virtual void save (const String &filename) const
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 
virtual void write (FileStorage &fs) const
 将算法参数存储到文件存储中。
 
void write (FileStorage &fs, const String &name) const
 

静态公共成员函数

static Ptr< RNNLayercreate (const LayerParams &params)
 
- 继承自 cv::Algorithm 的静态公共成员函数
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 从文件中加载算法。
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 从字符串加载算法。
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 从文件节点读取算法。
 

额外继承成员

- 继承自 cv::dnn::Layer 的公共属性
std::vector< Matblobs
 学习到的参数列表必须存储在此处,以便可以通过 Net::getParam() 读取它们。
 
String name
 层实例的名称,可用于日志记录或其他内部目的。
 
int preferableTarget
 层转发的首选目标
 
String type
 通过层工厂创建层时使用的类型名称。
 
- 继承自 cv::Algorithm 的保护成员函数
void writeFormat (FileStorage &fs) const
 

详细描述

经典的循环层。

接受两个输入 \(x_t\) 和 \(h_{t-1}\),并计算两个输出 \(o_t\) 和 \(h_t\)。

  • input: 应包含打包的输入 \(x_t\)。
  • output: 应包含输出 \(o_t\) (如果 setProduceHiddenOutput() 设置为 true,则包含 \(h_t\))。

input[0] 的形状应为 [T, N, data_dims],其中 TN 分别是时间戳的数量和 \(x_t\) 的独立样本数量。

output[0] 的形状将为 [T, N, \(N_o\)],其中 \(N_o\) 是 \( W_{xo} \) 矩阵中的行数。

如果 setProduceHiddenOutput() 设置为 true,则 output[1] 将包含一个形状为 [T, N, \(N_h\)] 的 Mat,其中 \(N_h\) 是 \( W_{hh} \) 矩阵中的行数。

成员函数文档

◆ create()

static Ptr< RNNLayer > cv::dnn::RNNLayer::create ( const LayerParams & params)
static

创建 RNNLayer 实例

◆ setProduceHiddenOutput()

virtual void cv::dnn::RNNLayer::setProduceHiddenOutput ( bool produce = false)
纯虚函数

如果此标志设置为 true,则层将生成 \( h_t \) 作为第二个输出。

第二个输出的形状与第一个输出相同。

◆ setWeights()

virtual void cv::dnn::RNNLayer::setWeights ( const Mat & Wxh,
const Mat & bh,
const Mat & Whh,
const Mat & Who,
const Mat & bo )
纯虚函数

设置学习到的权重。

循环层在每个步骤的行为由当前输入 \( x_t \)、前一状态 \( h_t \) 和学习到的权重定义如下:

\begin{eqnarray*} h_t &= tanh&(W_{hh} h_{t-1} + W_{xh} x_t + b_h), \\ o_t &= tanh&(W_{ho} h_t + b_o), \end{eqnarray*}

参数
Wxh是 \( W_{xh} \) 矩阵
bh是 \( b_{h} \) 向量
Whh是 \( W_{hh} \) 矩阵
Who是 \( W_{xo} \) 矩阵
bo是 \( b_{o} \) 向量

此类的文档生成自以下文件