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.htmlhttp://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 深度可分离卷积