当前位置:网站首页>什么是算子?
什么是算子?
2022-06-25 18:34:00 【华为云开发者联盟】
摘要:本文介绍什么是算子,算子有哪些基本特征。
本文分享自华为云社区《【CANN文档速递05期】一文让您了解什么是算子》,作者: 昇腾CANN 。
什么是算子
深度学习算法由一个个计算单元组成,我们称这些计算单元为算子(Operator,简称OP)。在网络模型中,算子对应层中的计算逻辑,例如:卷积层(Convolution Layer)是一个算子;全连接层(Fully-connected Layer, FC layer)中的权值求和过程,是一个算子。
再例如:tanh、ReLU等,为在网络模型中被用做激活函数的算子。

算子的名称(Name)与类型(Type)
- 算子的名称:标识网络中的某个算子,同一网络中算子的名称需要保持唯一。
- 算子的类型:网络中每个算子根据算子类型进行实现逻辑的匹配,在一个网络中同一类型的算子可能存在多个。
如下图所示,Conv1、Pool1、Conv2都是此网络中的算子名称,其中Conv1与Conv2算子的类型都为Convolution,表示分别做一次卷积计算。

张量(Tensor)
- 张量是算子计算数据的容器,包括输入数据与输出数据。
- 张量描述符(TensorDesc)是对输入数据与输出数据的描述,主要包含如下属性:

下面我们详细介绍下张量描述符中的形状和数据排布格式。
形状(Shape)
张量的形状,比如形状(3,4)表示第一维有3个元素,第二维有4个元素,是一个3行4列的矩阵数组。在形状中有多少个数字,就代表这个张量有多少维。形状的第一个元素要看张量最外层的中括号中有几个元素,形状的第二个元素要看张量中从左边开始数第二个中括号中有几个元素,依此类推。例如:

下面我们看一下形状的物理含义,假设shape=(4, 20, 20, 3)。
假设有4张照片,即shape里4的含义,每张照片的宽和高都是20,也就是20*20=400个像素,每个像素点都由红/绿/蓝3色组成,即shape里面3的含义,这就是shape=(4, 20, 20, 3)的物理含义。

数据排布格式
在深度学习领域,多维数据通过多维数组存储,比如卷积神经网络的特征图(Feature Map)通常用四维数组保存,即4D格式:
- N:Batch数量,例如图像的数目。
- H:Height,特征图高度,即垂直高度方向的像素个数。
- W:Width,特征图宽度,即水平宽度方向的像素个数。
- C:Channels,特征图通道,例如彩色RGB图像的Channels为3。
由于数据只能线性存储,因此这四个维度有对应的顺序。不同深度学习框架会按照不同的顺序存储特征图数据,比如Caffe,排列顺序为[Batch, Channels, Height, Width],即NCHW。TensorFlow中,排列顺序为[Batch, Height, Width, Channels],即NHWC。
以一张格式为RGB的图片为例,NCHW中,C排列在外层,实际存储的是“RRRRRRGGGGGGBBBBBB”,即同一通道的所有像素值顺序存储在一起;而NHWC中C排列在最内层,实际存储的则是“RGBRGBRGBRGBRGBRGB”,即不同通道的同一位置的像素值顺序存储在一起。

尽管存储的数据相同,但不同的存储顺序会导致数据的访问特性不一致,因此即便进行同样的运算,相应的计算性能也会不同。
在昇腾AI处理器中,为了提高数据的访问效率,张量数据采用NC1HWC0的五维格式。其中C0与微架构强相关,等于AI Core中矩阵计算单元的大小,这部分数据需要连续存储;C1是将C维度按照C0进行拆分后的数目,即C1=C/C0。如果不整除,最后一份数据需要补齐以对齐C0。
更多介绍
了解更详细的内容,可以登录昇腾社区昇腾社区-官网丨昇腾万里 让智能无所不及,阅读相关文档。
边栏推荐
- solidity获取季度时间
- Redis configuration (Internet access, password)
- mysql事务讲解
- Batch uploading of local jar packages to nexus private server
- TCP/IP 测试题(三)
- 解决sublime Text3 package control 无法安装插件问题
- 网络安全检测与防范 测试题(五)
- Addition, deletion, modification and query of mysql~ tables (detailed and easy to understand)
- Analysis on planting area, output and import of sugarcane in Guangxi in 2021: the output of sugarcane in Guangxi accounts for 68.56% of the total output of sugarcane in China [figure]
- Skills to master in advanced development
猜你喜欢
![[deeply understand tcapulusdb technology] transaction execution of document acceptance](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[deeply understand tcapulusdb technology] transaction execution of document acceptance

Pycharm 使用过程中碰到问题
![[in depth understanding of tcapulusdb technology] tcapulusdb regular documents](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[in depth understanding of tcapulusdb technology] tcapulusdb regular documents

158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts

【深入理解TcaplusDB技术】TcaplusDB常规单据

Redis command string

Idea annotation color modification method (clear)

JVM understanding

初探Oracle全栈虚拟机---GraalVM

【深入理解TcaplusDB技術】TcaplusDB業務數據備份
随机推荐
Class 02 loader subsystem
C generic class case
【深入理解TcaplusDB技術】TcaplusDB業務數據備份
Use pagoda to set up mqtt server
[deeply understand tcapulusdb technology] create a game area for document acceptance
焕新出发,利尔智达天下
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance
RMAN backup database_ Use RMAN for split mirror backup
Redis configuration (Internet access, password)
Skills to master in advanced development
solidity 合约地址转钱包、钱包地址转合约
如何快速关闭8080端口
Redis command string
Web development solution to cross domain problems
Redis 5.0 data structure double end linked list source code analysis
【深入理解TcaplusDB技术】Tmonitor后台一键安装
Move graph explorer to jupyterab: use ges4jupyter to connect ges and explore graphs
Dell R530内置热备盘状态变化说明
解决sublime Text3 package control 无法安装插件问题
[deeply understand tcapulusdb technology] transaction execution of document acceptance