Padding in tensorflow

之前每次在算卷积层和pooling 层的输出size的时候都很头疼,感觉不知道别人的代码是怎么算的,仔细研究了一下padding 这个参数才知道

Padding

tensorflow 的 conv2d 和max_pool 里面都用到了 有 'SAME' 和 ‘VALID' 两种模式,这两种不同的模式下计算output size的方式不一样

Notation
  • S: stride size
  • K: kernel size
SAME model

SAME model 下 output size 和 input size的关系是

out_height = ceil(float(in_height) / float(strides[1]))
out_width = ceil(float(in_width) / float(strides[2]))

tensorflow 会自动加上一些padding element 去填充Input tensor 使得out_height, out_width尽量取整

VALID model

VALID model 就是传统的计算方式, output size 和 input size 的关系是

out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))

Reference

http://stackoverflow.com/questions/37674306/what-is-the-difference-between-same-and-valid-padding-in-tf-nn-max-pool-of-t

http://www.jianshu.com/p/05c4f1621c7e

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容