Tensorflow中padding的两种类型SAME和VALID
来源:互联网 发布:淘宝电器销售额 编辑:程序博客网 时间:2024/05/22 05:17
边界补充问题
原始图片尺寸为7*7,卷积核的大小为3*3,当卷积核沿着图片滑动后只能滑动出一个5*5的图片出来,这就造成了卷积后的图片和卷积前的图片尺寸不一致,这显然不是我们想要的结果,所以为了避免这种情况,需要先对原始图片做边界填充处理。在上面的情况中,我们需要先把原始图像填充为9*9的尺寸。
常用的区域填充方法包括:
用3*3定义原始图像的尺寸,补充为9*9的尺寸,图片上的颜色只为方便观看,并没有任何其他含义。
原始图像:
(1)补零
(2)边界复制
(3)镜像
(4)块复制
更多理解见
理解图像卷积操作的意义
padding的方式:
备注
"VALID" only ever drops the right-most columns (or bottom-most rows). "SAME" tries to pad evenly left and right, but if the amount of columns to be added is odd, it will add the extra column to the right, as is the case in this example (the same logic applies vertically: there may be an extra row of zeros at the bottom).
不同的padding方式,VALID是采用丢弃的方式,比如上述的input_width=13,只允许滑动2次,多余的元素全部丢掉SAME的方式,采用的是补全的方式,对于上述的情况,允许滑动3次,但是需要补3个元素,左奇右偶,在左边补一个0,右边补2个0
Tensorflow中的定义
The TensorFlow Convolution example gives an overview about the difference between SAME and VALID : For the SAME padding, the output height and width are computed as: out_height = ceil(float(in_height) / float(strides[1])) out_width = ceil(float(in_width) / float(strides[2]))And For the VALID padding, the output height and width are computed as: out_height = ceil(float(in_height - filter_height + 1) / float(strides1)) out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))
备注
#SAME 向上取整#VALID 向下取整
x = tf.constant([[1., 2., 3.], [4., 5., 6.]])x = tf.reshape(x, [1, 2, 3, 1]) # give a shape accepted by tf.nn.max_poolvalid_pad = tf.nn.max_pool(x, [1, 2, 2, 1], [1, 2, 2, 1], padding='VALID')same_pad = tf.nn.max_pool(x, [1, 2, 2, 1], [1, 2, 2, 1], padding='SAME')valid_pad.get_shape() == [1, 1, 1, 1] # valid_pad is [5.]same_pad.get_shape() == [1, 1, 2, 1] # same_pad is [5., 6.]
参考文献:
TensorFlow中CNN的两种padding方式“SAME”和“VALID”
https://stackoverflow.com/questions/37674306/what-is-the-difference-between-same-and-valid-padding-in-tf-nn-max-pool-of-t
Tensorflow中padding的两种类型SAME和VALID
阅读全文
0 0
- Tensorflow中padding的两种类型SAME和VALID
- Tensorflow中padding的两种类型SAME和VALID
- Tensorflow中padding的两种类型SAME和VALID
- Tensorflow中padding的两种类型SAME和VALID
- Tensorflow中padding的两种类型SAME和VALID
- Tensorflow中padding的两种类型SAME和VALID
- TensorFlow中CNN的两种padding方式“SAME”和“VALID”
- TensorFlow中CNN的两种padding方式“SAME”和“VALID”
- Tensorflow里的padding操作(VALID和SAME两种)
- tensorflow中padding的两种类型对比
- tensorflow:SAME VALID padding
- [AI, 深度学习] tensorflow中padding="SAME"和"VALID"的区别
- 卷积神经网络中same padding 和 valid padding
- tensorflow_conv2d_max_pool卷积池化padding参数为SAME和VALID的区别
- tensorflow中padding方式理解:same与valide
- tf的“SAME”和“VALID”
- tensorflow中nn的padding
- caffe和tensorflow中padding区别
- 嵌入式中为何需要Jlink、SD卡等辅助设备
- sprintf和swprintf
- Java设计模式之结构型模式-适配器模式(Adapter)
- java实现数组元素全排列
- 23-SpringBoot——核心-Favicon配置
- Tensorflow中padding的两种类型SAME和VALID
- 【JZOJ5332】密码
- 【23种设计模式】结构型模式 > 桥接模式
- 下跌尽头线
- Angular购物车
- 多方炮
- 计算机二级c随笔一
- shoppingcart基础页面
- Understand on the tf.variable_scope and tf.name_scope