深度可分离卷积

  顾名思意,Depthwise可理解为逐深度,深度可分离卷积就是逐个深度分开卷积,也就是逐个通道分开卷积,
如下图:

 

 假设原来是3*3的卷积,那么depthwise separable convolution就是先用M个3*3卷积核一对一卷积输入的M个feature map,不求和,生成M个结果;然后用N个1*1的卷积核正常卷积前面生成的M个结果,求和,最后生成N个结果。

直接上pytorch代码:

class CSDN_Tem(nn.Module):
def __init__(self, in_ch, out_ch):
super(CSDN_Tem, self).__init__()
self.depth_conv = nn.Conv2d(
in_channels=in_ch,
out_channels=in_ch,
kernel_size=3,
stride=1,
padding=1,
groups=in_ch
)
self.point_conv = nn.Conv2d(
in_channels=in_ch,
out_channels=out_ch,
kernel_size=1,
stride=1,
padding=0,
groups=1
)

def forward(self, input):
out = self.depth_conv(input)
out = self.point_conv(out)
return out

替代后训练发现,和原来的3*3普通卷积效果相同。

posted @ 2022-05-16 16:30  阿呦33  阅读(604)  评论(0)    收藏  举报