今天研究了一下卷积计算。
卷积涉及到的两个输入为: 图像和filter
图像: 维度为
C*H*W
C是channel, 也叫做 depth, H和W就是图像的宽和高了。filter, 维度为
K*K
, 假设 filter的个数为 M个
直接进行卷积的伪代码为
for w in 1..W (img_width)
for h in 1..H (img_height)
for x in 1..K (filter_width)
for y in 1..K (filter_height)
for m in 1..M (num_filters)
for c in 1..C (img_channel)
output(w, h, m) += input(w+x, h+y, c) * filter(m, x, y, c)
end
end
end
end
end
end
卷积之后的输出的维度为 num_filter* out_h * out_w
注意out_h 和 out_w 是img_h, img_w经过pading 和stride之后的宽高,计算公式为:
hout=