tf.nn.conv2d 和 tf.nn.max_pool 中 padding 分别为 'VALID' 和 'SAME' 的直觉上的经验和测试代码
这个地方一开始是迷糊的,写代码做比较分析,总结出直觉上的经验.
某人若想看精准的解释,移步这个网址(http://blog.csdn.net/fireflychh/article/details/73743849),但我觉得直觉上的经验更有用,如下:
直觉上的经验:
- 一件确定的事: padding 无论取 'SAME' 还是取 'VALID', 它在 conv2d 和 max_pool 上的表现是一致的;
- padding = 'SAME' 时,输出并不一定和原图size一致,但会保证覆盖原图所有像素,不会舍弃边上的莫些元素;
- padding = 'VALID' 时,输出的size总比原图的size小,有时不会覆盖原图所有元素(既,可能舍弃边上的某些元素).
# -*- coding: utf-8 -*-
import tensorflow as tf
import numpy as np
def pooling_show():
a = tf.Variable(tf.random_normal(X))
pooling = tf.nn.max_pool(a, pooling_filter, pooling_strides, padding=pad)
# VALID (1, 2, 2, 7)
# SAME (1, 3, 3, 7)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print 'image: '
image = sess.run(a)
print image.shape
print 'pooling result: '
res = sess.run(pooling)
print res.shape
def conv2d_padding_show():
# [1, 13, 13, 2] ---> [m, height, width, channel]
input = tf.Variable(tf.random_normal(X))
# [6, 6, 2, 7] ---> [height, width, prev_channel, output_channel]
filter = tf.Variable(tf.random_normal(conv2d_filter))
op = tf.nn.conv2d(input, filter, strides=conv2d_strides, padding=pad)
# VALID (1, 2, 2, 7)
# SAME (1, 3, 3, 7)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print 'image: '
image = sess.run(input)
print image.shape
print 'result: '
res = sess.run(op)
print res.shape
pad = 'VALID'
# X ---> [m, height, width, channel]
# X = [1, 13, 13, 7]
X = [1, 8, 8, 3]
# ---> [1, f, f, 1]
# pooling_filter = [1, 6, 6, 1]
pooling_filter = [1, 2, 2, 1]
# ---> [1, s, s, 1]
# pooling_strides = [1, 5, 5, 1]
pooling_strides = [1, 2, 2, 1]
# ---> [height, width, prev_channel, output_channel]
# conv2d_filter = [6, 6, 7, 7]
conv2d_filter = [2, 2, 3, 3]
# ---> [1, s, s, 1]
# conv2d_strides = [1, 5, 5, 1]
conv2d_strides = [1, 2, 2, 1]
# 自己改改 X, fileter, strides 的值,配合直觉经验,会有更好的理解
conv2d_padding_show()
pooling_show()
tf.nn.conv2d 和 tf.nn.max_pool 中 padding 分别为 'VALID' 和 'SAME' 的直觉上的经验和测试代码的更多相关文章
- Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完成测试代码)
MD5和RSA是网络传输中最常用的两个算法,了解这两个算法原理后就能大致知道加密是怎么一回事了.但这两种算法使用环境有差异,刚好互补. 一.MD5算法 首先MD5是不可逆的,只能加密而不能解密.比如明 ...
- Pytorch中nn.Conv2d的用法
Pytorch中nn.Conv2d的用法 nn.Conv2d是二维卷积方法,相对应的还有一维卷积方法nn.Conv1d,常用于文本数据的处理,而nn.Conv2d一般用于二维图像. 先看一下接口定义: ...
- 关于torch.nn.Conv2d的笔记
先看一下CLASS有哪些参数: torch.nn.Conv2d( in_channels, out_channels, kernel_size, stride=1, padding=0, dilati ...
- PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx
PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx 在写 PyTorch 代码时,我们会发现一些功能重复的操作,比如卷积.激活.池化等操作.这些操作分别可 ...
- 深度学习原理与框架-Tensorflow卷积神经网络-卷积神经网络mnist分类 1.tf.nn.conv2d(卷积操作) 2.tf.nn.max_pool(最大池化操作) 3.tf.nn.dropout(执行dropout操作) 4.tf.nn.softmax_cross_entropy_with_logits(交叉熵损失) 5.tf.truncated_normal(两个标准差内的正态分布)
1. tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='SAME') # 对数据进行卷积操作 参数说明:x表示输入数据,w表示卷积核, stride ...
- tf.nn.conv2d函数和tf.nn.max_pool函数介绍
tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) 介绍参数: input:指卷积需要输入的 ...
- TF-卷积函数 tf.nn.conv2d 介绍
转自 http://www.cnblogs.com/welhzh/p/6607581.html 下面是这位博主自己的翻译加上测试心得 tf.nn.conv2d是TensorFlow里面实现卷积的函数, ...
- tf.nn.conv2d。卷积函数
tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个方法,非常重要 tf.nn.conv2d(input, fil ...
- tf.nn.conv2d
tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) input: 指需要做卷积的输入图像,它 ...
随机推荐
- IDEA里面创建maven项目,依赖
在IDEA里面创建一个简单的Maven项目: 在file-->new-->project ,选择maven,点击next 里面的一些简单参数的定义(第一次使用的话可以使用默认的值进行后面的 ...
- 基于UDP协议的控制台聊天程序(c++版)
本博客由Rcchio原创,转载请告知作者 ------------------------------------------------------------------------------- ...
- Java Servlet(十一):一个servlet被10个浏览器客户端访问时会创建几个servlet实例?
一般Servlet只初始化一次(只有一个实例).对于更多的客户端请求,Server创建新的请求和响应对象,仍然激活此Servlet的service()方法,将这两个对象作为参数传递给该方法.如此重复以 ...
- 南京邮电大学java程序设计作业在线编程第四次作业
王利国的的 "Java语言程序设计第4次作业(2018)" 详细 主页 我的作业列表 作业结果详细 总分:100 选择题得分:40 1.下列方法定义中,正确的是() A.doub ...
- javascript中的事件类型
表单事件 submit reset click change focus blur input window事件 load DomContentLoaded readyStatechange unlo ...
- jQuery系列 第三章 jQuery框架操作CSS
第三章 jQuery框架操作CSS 3.1 jQuery框架的CSS方法 jQuery框架提供了css方法,我们通过调用该方法传递对应的参数,可以方便的来批量设置标签的CSS样式. 使用JavaScr ...
- 【webstorm使用手册】如何让webstorm支持nextcss基础语法?
第一步, 安装 PostCss插件 如果不知道如何安装插件,参看:http://www.cnblogs.com/codelovers/p/7048113.html 第二步,设置文件类型解析方式 打开F ...
- LoadRunner菜鸟入门学习笔记
一.LR版本及浏览器选择 1.首先百度了一下LR各版本的浏览器兼容性 8.0 最高ie6 8.1 最高ie6 9.0 最高ie7 9.5 最高ie8 11.0 最高ie9( win7 32位+LR11 ...
- [测试题]line
Description Input Output Sample Input 10 49743636 36679 707182 9310618 9814768 2315242 9916077 35233 ...
- [NOIp 2016]天天爱跑步
Description 小C同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.<天天爱跑步>是一个养成类游戏,需要玩家每天按时上线,完成打卡任务. 这个游戏的地图 ...