【转载】 Tensorflow中padding的两种类型SAME和VALID
原文地址:
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:
If you like ascii art:
In this example:
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).
不同的padding方式,VALID是采用丢弃的方式,比如上述的input_width=
13
,只允许滑动
2
次,多余的元素全部丢掉。
SAME的方式,采用的是补全的方式,对于上述的情况,允许滑动
3
次,但是需要补
3
个元素,左奇右偶,在左边补一个
0
,右边补
2
个
0 。
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的更多相关文章
- AspNetWebApi管线中如果定义两种类型的消息处理程序(全局/路由)
AspNetWebApi管线中如果定义两种类型的消息处理程序(全局/路由) 在AspNetWebApi管线中存在两种类型的消息处理程序(Message Handler) 1.全局消息处理程序,所有的请 ...
- TensorFlow中CNN的两种padding方式“SAME”和“VALID”
来源 dilation_rate为一个可选的参数,默认为1,这里我们可以先不管它. 整理一下,对于"VALID",输出的形状计算如下: new_height=new_width=⌈ ...
- java中线程分两种,守护线程和用户线程。
java中线程分为两种类型:用户线程和守护线程. 通过Thread.setDaemon(false)设置为用户线程: 通过Thread.setDaemon(true)设置为守护线程. 如果不设置次属性 ...
- JavaScript中两种类型的全局对象/函数【转】
Snandy Stop, thinking is the essence of progress. JavaScript中两种类型的全局对象/函数 这里所说的JavaScript指浏览器环境中的包括宿 ...
- 【转载】JAVA中线程的两种实现方法-实现Runnable接口和继承Thread类
转自: http://blog.csdn.net/sunguangran/article/details/6069317 非常感谢原作者,整理的这么详细. 在java中可有两种方式实现多线程,一种是继 ...
- 协议中UART的两种模式 【转】
转自:http://wjf88223.blog.163.com/blog/static/3516800120104179327286/ ^^…… 协议栈中UART有两种模式:1.中断2.DMA 对于这 ...
- .NET环境下导出Excel表格的两种方式和导入两种类型的Excel表格
一.导出Excel表格的两种方式,其中两种方式指的是导出XML数据类型的Excel(即保存的时候可以只需要修改扩展名为.xls)和真正的Excel这两种. using System; using Sy ...
- C++ Primer学习笔记(三) C++中函数是一种类型!!!
C++中函数是一种类型!C++中函数是一种类型!C++中函数是一种类型! 函数名就是变量!函数名就是变量!函数名就是变量! (---20160618最新消息,函数名不是变量名...囧) (---201 ...
- 从上面的集合框架图可以看到,Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射
从上面的集合框架图可以看到,Java 集合框架主要包括两种类型的容器,一种是集合(Collection),存储一个元素集合,另一种是图(Map),存储键/值对映射.Collection 接口又有 3 ...
随机推荐
- 生成1~n的排列(模板),生成可重集的排列(对应紫书P184, P185)
生成1~n的排列: #include<iostream> using namespace std; void print_permutation(int n, int *A, int cu ...
- web 错误代码解析
404表示文件或资源未找到java WEB常见的错误代码1.1xx-信息提示:这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个1xx响应.100-继续.101-切换协议.2. ...
- 个性化排序算法实践(四)——GBDT+LR
本质上GBDT+LR是一种具有stacking思想的二分类器模型,所以可以用来解决二分类问题.这个方法出自于Facebook 2014年的论文 Practical Lessons from Predi ...
- Tomcat8服务
Windows部署Tomcat8服务在windows上部署Tomcat服务后,可以将Tomcat设为开机启动,即开机后Tomcat就会自动运行.这样就不用每次进到Tomcat的bin目录双击start ...
- c++中形参为引用和非引用时调用构造函数
#include<iostream> using namespace std; class numbered { private:static int seq; public: numbe ...
- Kubernetes 学习8 Pod控制器
一.回顾 1.Pod是标准的kubernetes资源,因此其遵循为其资源清单配置定义的基本格式,包含:apiVersion,kind,metadata,spec,status(只读) 2.spec的内 ...
- Linux系统性能10条命令
概述 通过执行以下命令,可以在1分钟内对系统资源使用情况有个大致的了解. uptime dmesg | tail vmstat 1 mpstat -P ALL 1 pidstat 1 iostat - ...
- 使用状态文件+vigil 监控系统状态
vigil 是一个不错的系统可用性报告系统,具有还不错的ui 界面,同时也有通知配置,以下是一个简单的 demo 使用状态文件,以及http body 匹配的模式进行web 应用状态的监控,只是简单的 ...
- Ubuntu下面删除和卸载软件
1.卸载nginx 1)首先执行第一条命令查出想关的软件包: dpkg --get-selections | grep nginx 2)开始执行卸载列出的common 和core 这个2个安装包 一个 ...
- 洛谷 P1901 发射站 题解
P1901 发射站 题目描述 某地有 N 个能量发射站排成一行,每个发射站 i 都有不相同的高度 Hi,并能向两边(当 然两端的只能向一边)同时发射能量值为 Vi 的能量,并且发出的能量只被两边最近的 ...