Tensorflow卷积接口总结

tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None)

这个接口用了这么久,每次都有点迷惑,这里做下总结。

  • 参数

input:输入图片,shape为[batch_size, in_height, in_width, in_channels]

filter:卷积核参数,shape为[kernel_height, kernel_width, in_channels, out_channels],第三维与input的第四维对应,第四维决定了卷积核的个数

stride:步长,一维向量,4个值,其中[0]和[3]固定填写1,[2]和[4]分别为height的步长和width的步长,即[1,h,w,1]

padding:对齐方式,取值valid则丢弃剩余不能和kernel size匹配的图像元素,取值same则对图像元素做边缘扩充,扩充方式为左单右双。

  • 输出大小

根据以上参数可以计算出feature map的大小

out_height = (in_height - filter.height +2*padding)/stride + 1

out_width = (in_width - filter.width + 2*padding)/stride +1

  • 典型代码

一般来说都要配以tf.nn.bias_add来服用,添加bias参数。

原文地址:https://www.cnblogs.com/punkcure/p/8304264.html