计算卷积后尺寸

来源:互联网 发布:.blog域名 编辑:程序博客网 时间:2024/04/30 03:17

这里单独把计算卷积之后的维度的公式拿出来,方便查看
1.卷积后尺寸计算
out_height=(in_height+2pad-filter_height)/strides[1]+1
out_width=(in_width+2pad-filter_width)/strides[2] +1
2.tensorflow中卷积参数same和valid运算之后的维度计算
(1)same
out_height=ceil(float(in_height))/float(strides[1])
out_width=ceil(float(in_width))/float(strides[2])
(2)valid
out_height=ceil(float(in_height-filter_height+1))/float(strides[1])
out_width=ceil(float(in_width-filter_width+1))/float(strides[2])
(3)参数
padding: SAME和VALID两种形式
filter: [5,5,1,32]表示5*5的卷积核,1个channel,32个卷积核。
strides: [1,4,4,1]表示横向和竖向的步长都为4
3.tensorflow里面的tf.pad函数
虽然在卷积过程中有same选项可选,但是tensorflow里面还有一个可以用于填充的函数tf.pad(),具体用法如下:

tf.pad(tensor, paddings,mode='CONSTANT',name=None)

padings : 是一个张量,代表每一维填充多少行/列
mode : “CONSTANT” ,”REFLECT”,”SYMMETRIC”
“CONSTANT” 填充0, “REFLECT”是映射填充,上下(1维)填充顺序和paddings是相反的,左右(零维)顺序补齐, “SYMMETRIC”是对称填充,上下(1维)填充顺序是和paddings相同的,左右(零维)对称补齐