考虑到有些同学没有学习过深度学习的概念基础, 所以我们以简单的图示来表示卷积算子的计算过程.
现在有一个大小为4 × 4 × 3
的输入特征图, 4表示特征图的长和宽, 3表示其通道数量, 不同颜色表示不同的通道. 左边是我们的输入特征图, 右边3个是3 × 3 × 3
的卷积核, 为了叙述方便, 我们将3个卷积核分别表示为group1
, group2
和group3
. 每组中共有1个卷积核,每个卷积核的尺度用3个维度来表示, 分别为它的通道数(channel), 卷积核的长度(height)和卷积核的宽度(width).
在上图中, 卷积核的通道数(channel)为3, 卷积核的长和宽分别也都是3. 需要注意的是卷积核和输入特征中的通道数量要相同, 在本图例中就都是3. 卷积操作逐组, 逐个通道并按照滑动窗口的方式进行运算. 如下图所示, 是第一组(group1
)对输入特征图按照通道顺序对应进行卷积运算的操作过程, 时刻要记得在这里一个group
表示一个卷积核.
一个组内的卷积核中按通道维对输入特征图进行卷积运算, group1
中的第1个通道对输入特征图中的第1个通道(红色部分)进行卷积运算, group1
中的第2个通道对输入特征图中的第2个通道(绿色)部分进行卷积运算, group1
中的第2个通道同理. 最后将三个通道在第1个窗口内的卷积计算结果相加, 得到最后的结果, 有如下的公式所示:
o u t p u t c h a n n e l 1 = 1 × 1 + 1 × 2 + 1 × 3 + 2 × 5 + 2 × 6 + 2 × 7 + 3 × 7 + 3 × 8 + 3 × 9 = 114 o u t p u t c h a n n e l 2 = 1 × 1 + 1 × 2 + 1 × 3 + 2 × 5 + 2 × 6 + 2 × 7 + 3 × 7 + 3 × 8 + 3 × 9 = 114 o u t p u t c h a n n e l 3 = 1 × 1 + 1 × 2 + 1 × 3 + 2 × 5 + 2 × 6 + 2 × 7 + 3 × 7 + 3 × 8 + 3 × 9 = 114 o u t p u t r e s u l t = o u t p u t c h a n n e l 1 + o u t p u t c h a n n e l 2 + o u t p u t c h a n n e l 3 = 342 \begin{align*} &output\, channel_1= 1\times1+1\times2+1\times3+2\times5+2\times6+2\times7+3\times7+3\times8+3\times9 = 114\\ & output\, channel_2= 1\times1+1\times2+1\times3+2\times5+2\times6+2\times7+3\times7+3\times8+3\times9 = 114 \\ &output\, channel_3= 1\times1+1\times2+1\times3+2\times5+2\times6+2\times7+3\times7+3\times8+3\times9 = 114 \\ &output\,result = output\,channel_1+output\,channel_2+output\,channel_3 = 342\\ \end{align*} outputchannel1=1×1+1×2+1×3+2×5+2×6+2×7+3×7+3×8+3×9=114outputchannel2=1×1+1×2+1×3+2×5+2×6+2×7+3×7+3×8+3×9=114outputchannel3=1×1+1×2+1×3+2×5+2×6+2×7+3×7+3×8+3×9=114outputresult=outputchannel1+outputchannel2+outputchannel3=342
由于卷积计算的方式是以滑动窗口的方式进行的, 一般是先按行滑动, 遇到一行的结束的时候再转到下一行, 所以下一个卷积窗口的计算位置如下图所示:
前两次滑动窗口下的卷积运算结果会放到输出特征图第1维上的(0,0)
和(0,1)
位置上.
第2次卷积计算如下公式:
o u t p u t c h a n n e l 1 = 1 × 2 + 1 × 3 + 1 × 4 + 2 × 6 + 2 × 7 + 2 × 8 + 3 × 8 + 3 × 9 + 3 × 10 = 132 o u t p u t c h a n n e l 2 = 1 × 2 + 1 × 3 + 1 × 4 + 2 × 6 + 2 × 7 + 2 × 8 + 3 × 8 + 3 × 9 + 3 × 10 = 132 o u t p u t c h a n n e l 3 = 1 × 2 + 1 × 3 + 1 × 4 + 2 × 6 + 2 × 7 + 2 × 8 + 3 × 8 + 3 × 9 + 3 × 10 = 132 o u t p u t r e s u l t = o u t p u t c h a n n e l 1 + o u t p u t c h a n n e l 2 + o u t p u t c h a n n e l 3 = 396 \begin{align*} &output\, channel_1= 1\times2+1\times3+1\times4+2\times6+2\times7+2\times8+3\times8+3\times9+3\times10 = 132\\ & output\, channel_2= 1\times2+1\times3+1\times4+2\times6+2\times7+2\times8+3\times8+3\times9+3\times10 = 132 \\ &output\, channel_3= 1\times2+1\times3+1\times4+2\times6+2\times7+2\times8+3\times8+3\times9+3\times10 = 132 \\ &output\,result = output\,channel_1+output\,channel_2+output\,channel_3 = 396\\ \end{align*} outputchannel1=1×2+1×3+1×4+2×6+2×7+2×8+3×8+3×9+3×10=132outputchannel2=1×2+1×3+1×4+2×6+2×7+2×8+3×8+3×9+3×10=132outputchannel3=1×2+1×3+1×4+2×6+2×7+2×8+3×8+3×9+3×10=132outputresult=outputchannel1+outputchannel2+outputchannel3=396
第3次的计算方式如下:
经过4次滑动窗口计算, 对应的输出特征图的第1个通道.
随后再使用group2
和 group3
卷积核分别得到输出特征图的第2和第3个通道数据, 最后得到的结果如下图所示:
Tips:
group
的数量未完代叙…