原文地址:

https://blog.csdn.net/jasonzzj/article/details/53930074

---------------------------------------------------------------------------------------

SAME means that the output feature map has the same spatial dimensions as the input feature map. Zero padding is introduced to make the shapes match as needed, equally on every side of the input map.

VALID means no padding.

Padding could be used in convolution and pooling operations.

Here, take pooling for example:

down vote

If you like ascii art:

  • "VALID" = without padding:

    1. inputs: 1 2 3 4 5 6 7 8 9 10 11 (12 13)
    2. |________________| dropped
    3. |_________________|
  • "SAME" = with zero padding:

    1. pad| |pad
    2. inputs
    3. |________________|
    4. |_________________|
    5. |________________|

In this example:

  • Input width = 13
  • Filter width = 6
  • Stride = 5

Notes:

  • "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).

"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,右边补20  。

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(strides[1]))

    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_pool
 
valid_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.]

----------------------------------------------------------------------------------------------------------------------------------

参考地址:

https://www.2cto.com/kf/201708/673033.html

https://www.tensorflow.org/versions/r0.9/api_docs/python/nn.html

【转载】 Tensorflow中padding的两种类型SAME和VALID的更多相关文章

  1. AspNetWebApi管线中如果定义两种类型的消息处理程序(全局/路由)

    AspNetWebApi管线中如果定义两种类型的消息处理程序(全局/路由) 在AspNetWebApi管线中存在两种类型的消息处理程序(Message Handler) 1.全局消息处理程序,所有的请 ...

  2. TensorFlow中CNN的两种padding方式“SAME”和“VALID”

    来源 dilation_rate为一个可选的参数,默认为1,这里我们可以先不管它. 整理一下,对于"VALID",输出的形状计算如下: new_height=new_width=⌈ ...

  3. java中线程分两种,守护线程和用户线程。

    java中线程分为两种类型:用户线程和守护线程. 通过Thread.setDaemon(false)设置为用户线程: 通过Thread.setDaemon(true)设置为守护线程. 如果不设置次属性 ...

  4. JavaScript中两种类型的全局对象/函数【转】

    Snandy Stop, thinking is the essence of progress. JavaScript中两种类型的全局对象/函数 这里所说的JavaScript指浏览器环境中的包括宿 ...

  5. 【转载】JAVA中线程的两种实现方法-实现Runnable接口和继承Thread类

    转自: http://blog.csdn.net/sunguangran/article/details/6069317 非常感谢原作者,整理的这么详细. 在java中可有两种方式实现多线程,一种是继 ...

  6. 协议中UART的两种模式 【转】

    转自:http://wjf88223.blog.163.com/blog/static/3516800120104179327286/ ^^…… 协议栈中UART有两种模式:1.中断2.DMA 对于这 ...

  7. .NET环境下导出Excel表格的两种方式和导入两种类型的Excel表格

    一.导出Excel表格的两种方式,其中两种方式指的是导出XML数据类型的Excel(即保存的时候可以只需要修改扩展名为.xls)和真正的Excel这两种. using System; using Sy ...

  8. C++ Primer学习笔记(三) C++中函数是一种类型!!!

    C++中函数是一种类型!C++中函数是一种类型!C++中函数是一种类型! 函数名就是变量!函数名就是变量!函数名就是变量! (---20160618最新消息,函数名不是变量名...囧) (---201 ...

  9. 从上面的集合框架图可以看到,Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射

    从上面的集合框架图可以看到,Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射.Collection 接口又有 3 ...

随机推荐

  1. 如何设置CentOS 7开机自动获取IP地址详解

    本例中以CentOS 7举例说明如何设置Linux开机自动获取IP地址和设置固定IP地址. 自动获取动态IP地址 1.输入“ip addr”并按回车键确定,发现无法获取IP(CentOS 7默认没有i ...

  2. linux简单的命令

    本文转自 https://www.cnblogs.com/pyyu/articles/9314206.html Linux命令行的组成结构 [root@oldboy_python ~]# [root@ ...

  3. (java)selenium webdriver学习,选择模块,点击下一页,获取当前url

    selenium webdriver学习,选择模块,点击下一页,获取当前url 查找下一页有多种方法,这里列举两种: isSelected()函数用于判断是否点击选中,返回Boolean类型 impo ...

  4. nginx添加系统服务(start|stop|restart|reload)

    nginx添加系统服务 1.编写脚本,名为nginx #vim /etc/init.d/nginx #!/bin/bash#chkconfig: - 99 20 #description: Nginx ...

  5. Go语言 - 数组 | 多维数组

    Array 数组是同一种数据类型元素的集合. 在Go语言中,数组从声明时就确定,使用时可以修改数组成员,但是数组大小不可变化. 1.数组 在定义阶段,长度和类型就固定了,以后不能更改 2.长度也是数组 ...

  6. Oracle 新增数据 insert into整理

    一.普遍的方法:insert into 表名(id,name,age,status,字段N) values('id','name','age','status','字段N');   --建议用这个   ...

  7. VS - ActionFilterAttribute

    Global.asax.cs public class MvcApplication : System.Web.HttpApplication { public static void Registe ...

  8. contextMenuEvent

    #include "mainwindow.h" #include "ui_mainwindow.h" #include <QDesktopWidget&g ...

  9. web基本概念

    一.互联网 互联网(英语:Internet),又称网际网络,或音译因特网(Internet).英特网,互联网始于1969年美国的阿帕网.是网络与网络之间所串连成的庞大网络,这些网络以一组通用的协议相连 ...

  10. mac clion c/c++环境配置

    下载安装:https://www.cnblogs.com/sea-stream/p/11220036.html 切换语言:https://www.cnblogs.com/sea-stream/p/11 ...