Padding in tensorflow

2017-02-06  本文已影响0人  Nocturne_L

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

Padding

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

Notation
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

上一篇 下一篇

猜你喜欢

热点阅读