前言

这个例子说明了什么叫做空间可分离卷积,这种方法并不应用在深度学习中,只是用来帮你理解这种结构。

在神经网络中,我们通常会使用深度可分离卷积结构(depthwise separable convolution)。

这种方法在保持通道分离的前提下,接上一个深度卷积结构,即可实现空间卷积。接下来通过一个例子让大家更好地理解。

算法原理

假设有一个3×3大小的卷积层,其输入通道为16、输出通道为32。具体为,32个3×3大小的卷积核会遍历16个通道中的每个数据,从而产生16×32=512个特征图谱。进而通过叠加每个输入通道对应的特征图谱后融合得到1个特征图谱。最后可得到所需的32个输出通道。

针对这个例子应用深度可分离卷积,用1个3×3大小的卷积核遍历16通道的数据,得到了16个特征图谱。在融合操作之前,接着用32个1×1大小的卷积核遍历这16个特征图谱,进行相加融合。这个过程使用了16×3×3+16×32×1×1=656个参数,远少于上面的16×32×3×3=4608个参数。

这个例子就是深度可分离卷积的具体操作,其中上面的深度乘数(depth multiplier)设为1,这也是目前这类网络层的通用参数。

这么做是为了对空间信息和深度信息进行去耦。从Xception模型的效果可以看出,这种方法是比较有效的。由于能够有效利用参数,因此深度可分离卷积也可以用于移动设备中。

下面的代码是mobilenet的一个参数列表,计算的普通卷积与深度分离卷积的计算复杂程度比较 : 代码链接

# Tensorflow mandates these.
from collections import namedtuple
import functoolsimport tensorflow as tfslim = tf.contrib.slim# Conv and DepthSepConv namedtuple define layers of the MobileNet architecture
# Conv defines 3x3 convolution layers
# DepthSepConv defines 3x3 depthwise convolution followed by 1x1 convolution.
# stride is the stride of the convolution
# depth is the number of channels or filters in a layer
Conv = namedtuple('Conv', ['kernel', 'stride', 'depth'])
DepthSepConv = namedtuple('DepthSepConv', ['kernel', 'stride', 'depth'])# _CONV_DEFS specifies the MobileNet body
_CONV_DEFS = [Conv(kernel=[3, 3], stride=2, depth=32),DepthSepConv(kernel=[3, 3], stride=1, depth=64),DepthSepConv(kernel=[3, 3], stride=2, depth=128),DepthSepConv(kernel=[3, 3], stride=1, depth=128),DepthSepConv(kernel=[3, 3], stride=2, depth=256),DepthSepConv(kernel=[3, 3], stride=1, depth=256),DepthSepConv(kernel=[3, 3], stride=2, depth=512),DepthSepConv(kernel=[3, 3], stride=1, depth=512),DepthSepConv(kernel=[3, 3], stride=1, depth=512),DepthSepConv(kernel=[3, 3], stride=1, depth=512),DepthSepConv(kernel=[3, 3], stride=1, depth=512),DepthSepConv(kernel=[3, 3], stride=1, depth=512),DepthSepConv(kernel=[3, 3], stride=2, depth=1024),DepthSepConv(kernel=[3, 3], stride=1, depth=1024)
]input_size = 160
inputdepth = 3
conv_defs = _CONV_DEFS
sumcost = 0
for i, conv_def in enumerate(conv_defs):stride = conv_def.stridekernel = conv_def.kerneloutdepth = conv_def.depthoutput_size = round((input_size - int(kernel[0] / 2) * 2) / stride)if isinstance(conv_def, Conv):sumcost += output_size * output_size * kernel[0] * kernel[0] * inputdepth * outdepthif isinstance(conv_def, DepthSepConv):sumcost += output_size * output_size * kernel[0] * kernel[0] * inputdepth * outdepthinputdepth = outdepthinput_size = output_size
print("src conv:    ", sumcost)input_size = 160
inputdepth = 3
conv_defs = _CONV_DEFS
sumcost1 = 0
for i, conv_def in enumerate(conv_defs):stride = conv_def.stridekernel = conv_def.kerneloutdepth = conv_def.depthoutput_size = round((input_size - int(kernel[0] / 2) * 2) / stride)if isinstance(conv_def, Conv):sumcost1 += output_size * output_size * kernel[0] * kernel[0] * inputdepth * outdepthif isinstance(conv_def, DepthSepConv):#sumcost += output_size * output_size * kernel[0] * kernel[0] * inputdepth * outdepthsumcost1 += output_size * output_size *(inputdepth * kernel[0] * kernel[0]  + inputdepth * outdepth * 1 * 1)inputdepth = outdepthinput_size = output_size
print("DepthSepConv:", sumcost1)
print("compare:", sumcost1 / sumcost)
src conv:       1045417824
DepthSepConv:   126373376
compare: 0.12088312739538674

深度可分离卷积结构(depthwise separable convolution)计算复杂度分析相关推荐

  1. 深度可分离卷积(DepthwiseSeparableConvolution):Depthwise卷积与Pointwise卷积

    0.前言 1.深度可分离卷积 1.1 depthwise卷积 1.2 pointwise卷积 2.代码实现 参考 0.前言 深度可分离卷积不用多说,在轻量级网络架构方面是一个绕不开的话题,只要接触深度 ...

  2. Lesson 16.1016.1116.1216.13 卷积层的参数量计算,1x1卷积核分组卷积与深度可分离卷积全连接层 nn.Sequential全局平均池化,NiN网络复现

    二 架构对参数量/计算量的影响 在自建架构的时候,除了模型效果之外,我们还需要关注模型整体的计算效率.深度学习模型天生就需要大量数据进行训练,因此每次训练中的参数量和计算量就格外关键,因此在设计卷积网 ...

  3. 对深度可分离卷积、分组卷积、扩张卷积、转置卷积(反卷积)的理解

    参考: https://zhuanlan.zhihu.com/p/28749411 https://zhuanlan.zhihu.com/p/28186857 https://blog.yani.io ...

  4. 深度可分离卷积Depthwise Separable Convolution

    从卷积神经网络登上历史舞台开始,经过不断的改进和优化,卷积早已不是当年的卷积,诞生了分组卷积(Group convolution).空洞卷积(Dilated convolution 或 À trous ...

  5. 【CV】MobileNet:使用深度可分离卷积实现用于嵌入式设备的 CNN 架构

    论文名称:MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications 论文下载:https:/ ...

  6. 深度可分离卷积(Xception 与 MobileNet)

    前言 从卷积神经网络登上历史舞台开始,经过不断的改进和优化,卷积早已不是当年的卷积,诞生了分组卷积(Group convolution).空洞卷积(Dilated convolution 或 À tr ...

  7. 可分离卷积及深度可分离卷积详解

    可分离卷积 再来看一下nn.Conv2d(): torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, ...

  8. 深度可分离卷积(Xception 相关)

    卷积神经网络经过不断的改进和优化,卷积早已不是当年的卷积,诞生了分组卷积(Group convolution).空洞卷积(Dilated convolution 或 À trous)等各式各样的卷积. ...

  9. Xception深度可分离卷积-论文笔记

    Xception Xception: Deep Learning with Depthwise Separable Convolutions 角度:卷积的空间相关性和通道相关性 . 笔记还是手写好,都 ...

  10. 通道可分离卷积 depth-wise separable convolution

    通道可分离卷积 文章目录 通道可分离卷积 正常卷积回顾 通道可分离卷积 通道分离卷积,depthwise separable convolution,也叫深度可分离卷积,是MobileNet系列的主要 ...

最新文章

  1. Sending e-mail with Spring MVC--转载
  2. future java 原理_Java线程池FutureTask实现原理详解
  3. TFS 路径...已在工作区...
  4. python编写一个登陆验证程序_python项目实战:实现验证码登录网址实例
  5. 计算机硬件系统的构成教学设计,2.1 计算机硬件系统教学设计思路
  6. android——获取ImageView上面显示的图片bitmap对象
  7. bcb6通过https接口post数据_Python+Requests+Pytest+YAML+Allure实现接口自动化
  8. 用HTML及CSS制作一个简易动画效果
  9. RealityCapture摄影测量软件
  10. 【001】快乐数字解题过程记录
  11. 迅捷ocr文字识别软件是如何将图片转成文字的?
  12. Transformer如何用于视频?最新「视频Transformer」2022综述
  13. 关于出现IllegalArgumentException异常的可能原因
  14. 辗转相除求最大公约数原理
  15. 我的物联网项目(十六) 项目工程
  16. Chart.js插件使用的笔记
  17. EPUB、CAJ 、PDF 格式的区别,有什么好用的IOS手机epub阅读器
  18. HTML5+CSS期末大作业:环保网站设计——动物保护网(6页) 大学生环境保护网页作品 环保网页设计作业模板 学生网页制作源代码下载...
  19. 论坛介绍 | COSCon'22 区块链(B)
  20. 网页设计基础——网页布局结构

热门文章

  1. 05月08日 学习列表
  2. Servlet 生命周期、工作原理(转)
  3. 电商网站主动取消客户已支付成功订单感想
  4. javascript js string.Format()收集
  5. Java中File类的separator属性
  6. 使用actuator优雅地停止SpringBoot应用
  7. 如何为SQL Server2008添加登录账户并配置权限
  8. Thingsboard 3.1.0 - 远程控制和GPIO状态显示
  9. 查找算法之四 斐波那契查找(C++版本)
  10. php 微信公众 验证失败,微信公众平台token验证失败