这个地方一开始是迷糊的,写代码做比较分析,总结出直觉上的经验.

某人若想看精准的解释,移步这个网址(http://blog.csdn.net/fireflychh/article/details/73743849),但我觉得直觉上的经验更有用,如下:

直觉上的经验:

  1. 一件确定的事: padding 无论取 'SAME' 还是取 'VALID', 它在 conv2d 和 max_pool 上的表现是一致的;
  2. padding = 'SAME' 时,输出并不一定和原图size一致,但会保证覆盖原图所有像素,不会舍弃边上的莫些元素;
  3. 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' 的直觉上的经验和测试代码的更多相关文章

  1. Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完成测试代码)

    MD5和RSA是网络传输中最常用的两个算法,了解这两个算法原理后就能大致知道加密是怎么一回事了.但这两种算法使用环境有差异,刚好互补. 一.MD5算法 首先MD5是不可逆的,只能加密而不能解密.比如明 ...

  2. Pytorch中nn.Conv2d的用法

    Pytorch中nn.Conv2d的用法 nn.Conv2d是二维卷积方法,相对应的还有一维卷积方法nn.Conv1d,常用于文本数据的处理,而nn.Conv2d一般用于二维图像. 先看一下接口定义: ...

  3. 关于torch.nn.Conv2d的笔记

    先看一下CLASS有哪些参数: torch.nn.Conv2d( in_channels, out_channels, kernel_size, stride=1, padding=0, dilati ...

  4. PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx

    PyTorch : torch.nn.xxx 和 torch.nn.functional.xxx 在写 PyTorch 代码时,我们会发现一些功能重复的操作,比如卷积.激活.池化等操作.这些操作分别可 ...

  5. 深度学习原理与框架-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 ...

  6. tf.nn.conv2d函数和tf.nn.max_pool函数介绍

    tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) 介绍参数: input:指卷积需要输入的 ...

  7. TF-卷积函数 tf.nn.conv2d 介绍

    转自 http://www.cnblogs.com/welhzh/p/6607581.html 下面是这位博主自己的翻译加上测试心得 tf.nn.conv2d是TensorFlow里面实现卷积的函数, ...

  8. tf.nn.conv2d。卷积函数

    tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个方法,非常重要 tf.nn.conv2d(input, fil ...

  9. tf.nn.conv2d

    tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, name=None) input: 指需要做卷积的输入图像,它 ...

随机推荐

  1. 高级控件 popwindow 与gridview的组合应用

    Gridview 的布局设置 <GridView android:layout_width="wrap_content" android:layout_height=&quo ...

  2. hdu 1880 魔咒字典

    https://vjudge.net/problem/HDU-1880 题意:略 思路: 一开始就是想到了正确的思路,但是代码写炸了,死活过不了.这题嘛,就是建议一个魔咒与咒语的双向映射.首先用字符串 ...

  3. 老男孩python学习之作业二---三级菜单

    因为之前花力气完成了购物小程序的作业 现在做这个三级菜单简直是so easy!! 1.显示省级菜单 2.交互,提示用户输入要查看的省份(退出e) 2.1.用户正确输入列表中的省份 3.显示市级菜单 3 ...

  4. git出现错误原因解释

    原因,在pull下拉代码或者push之前,你本地还有代码没有进行commit. 引起下面的错误.   建议commit后先pull再看看有没有冲突在进行push. git.exe push --pro ...

  5. 并发容器和框架之ConcurrentHashMap

    了解HashMap的人都知道HashMap是线程不安全的(多线程下的put方法达到一定大小,引发rehash,导致闭链,最终占满CPU),同时线程安全的HashTable效率又令人望而却步(每个方法都 ...

  6. POJ-3268 Silver Cow Party---正向+反向Dijkstra

    题目链接: https://vjudge.net/problem/POJ-3268 题目大意: 有编号为1-N的牛,它们之间存在一些单向的路径.给定一头牛的编号X,其他牛要去拜访它并且拜访完之后要返回 ...

  7. AngularJS 全局scope与指令 scope通信

    在项目开发时,全局scope 和 directive本地scope使用范围不够清晰,全局scope与directive本地scope通信掌握的不够透彻,这里对全局scope 和 directive本地 ...

  8. NGUI----简单聊天系统一

    1:聊天背景的创建 新建一个场景-----保存场景 NGUI---->Create-----Panel 选中UIRoot,然后新建一个sprite 选择图集 效果如下图 添加一个可拖拽的功能 选 ...

  9. Apache 安装与配置(WIN10)

    本地坏境:windows 10 Pro 1709 Apache版本:httpd-2.4.32-Win64-VC15 Apache下载地址:https://www.apachelounge.com/do ...

  10. Headless Chrome:服务端渲染JS站点的一个方案【上篇】【翻译】

    原文链接:https://developers.google.com/web/tools/puppeteer/articles/ssr 注:由于英文水平有限,没有逐字翻译,可以选择直接阅读原文 tip ...