caffe实现深度可分离卷积Depthwise Convolution

本文详细介绍了深度可分离卷积的原理,它由深度卷积和点卷积两部分组成,有效减少了计算量。通过实例展示了如何在Caffe中配置3x3的深度可分离卷积,包括depthwise卷积和pointwise卷积的参数设置。深度可分离卷积在移动设备上的应用广泛,因其高效性在模型压缩和加速方面具有显著优势。
摘要由CSDN通过智能技术生成

1、深度可分离卷积的原理(Depthwise Separable Convolution)

       深度可分离卷积由两个过程组成:depthwise convolution和pointwise convolution(即1x1 convolution)。

      不妨假设输入图像的高度和宽度相同,对于M个高度和宽度都为F 的输入特征图,先用M个K ∗K ∗ 1卷积核对M个通道的map进行的空间卷积,一个卷积核对应一个通道,得到通道数仍然为M的中间结果,再用N个1 ∗ 1 ∗ M的卷积核对中间结果进行标准卷积,得到深度可分离卷积结果。

2、实现3x3的深度可分离卷积

      a) depthwise convolution
      假设输入特征图为32通道,将group和num_output设置为32,将kernel_size设置为3,pad设置为1(保证卷积结果的高宽保持不变),stride设置为1。
group参数说明http://caffe.berkeleyvision.org/tutorial/layers/convolution.htmlicon-default.png?t=LA92http://caffe.berkeleyvision.org/tutorial/layers/convolution.html

group (g) [default 1]: If g > 1, we restrict the connectivity of each filter to a subset of the input. 
Specifically, the input and output channels are separated into g groups, 
and the ith output group channels will be only connected to the ith input group channels.

       将group、num_output设置为输入特征图的通道数,即可实现一个滤波器只与输入特征图的一个通道卷积。

layer {
  name: "conv_dw"
  type: "Convolution"
  bottom: "input_32"
  top: "conv_dw"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  convolution_param {
    num_output: 32
    bias_term: false
    pad: 1
    kernel_size: 3
    group: 32
    engine: CAFFE
    stride: 1
    weight_filler {
      type: "msra"
    }
  }
}

       b) pointwise convolution(1x1 convolution标准卷积)
      假设输入为前面的depthwise convolution的输出,pointwise convolution的输出结果的通道数为64。将num_output设置为64,kernel_size设置为1,pad设置为0。

layer {
  name: "conv_pw"
  type: "Convolution"
  bottom: "conv_dw"
  top: "conv_pw"
  param {
    lr_mult: 1
    decay_mult: 1
  }
  convolution_param {
    num_output: 64
    bias_term: false
    pad: 0
    kernel_size: 1
    stride: 1
    weight_filler {
      type: "msra"
    }
  }
}

深度学习:Depthwise卷积与Pointwise卷积_那年聪聪-CSDN博客Depthwise卷积与Pointwise卷积的优势及参数量https://blog.csdn.net/duan19920101/article/details/121884251参考:https://github.com/shicai/MobileNet-Caffe
转载自:caffe实现深度可分离卷积depthwise convolution_zhongqianli的专栏-CSDN博客_caffe 深度可分离卷积

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值