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

某人若想看精准的解释,移步这个网址(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. 访问远程的docker

        docker version vim /etc/default/docker DOCKER_OPTS="  -Label name=dockerserver2" docke ...

  2. OAuth2.0学习(1-10)新浪开放平台微博认证-手机应用授权和refresh_token刷新access_token

    1.当你是使用微博官方移动SDK的移动应用时,授权返回access_token的同时,还会多返回一个refresh_token: JSON 1 2 3 4 5 6 {     "access ...

  3. python 开发之路 - 入门

    一. python 介绍 Python是著名的"龟叔"Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言.1991年 发布Python ...

  4. libevent中evmap实现(哈希表)

    libevent中,需要将大量的监听事件event进行归类存放,比如一个文件描述符fd可能对应多个监听事件,对大量的事件event采用监听的所采用的数据结构是event_io_map,其实现通过哈希表 ...

  5. 涨薪必备Javascript,快点放进小口袋!

    摘要: 嗨,新一年的招聘季,你找到更好的工作了吗?小姐姐最近刚换的工作,来总结下面试必备小技能,从this来看看javascript,让我们更深入的了解它. 前言 在JavaScript中,被吐槽最多 ...

  6. jQuery.noConflict() 函数详解

    jQuery.noConflict()函数用于让出jQuery库对变量$(和变量jQuery)的控制权. 一般情况下,在jQuery库中,变量$是变量jQuery的别名,它们之间是等价的,例如jQue ...

  7. 八:Vue下的国际化处理

    p { margin-bottom: 0.25cm; line-height: 120% } 1:首先安装 Vue-i8n npm install vue-i18n --save 注:-save-de ...

  8. css 相关算法

    计算 em 目标像素 除 基准像素 等于 em倍数结果: 14 / 16 = 0.875em 0.875倍也就是 14 像素 计算百分比 目标像素 除 父类总宽度 乘 一百:90 / 200 * 10 ...

  9. mybatis学习成长之路(一)

    从小白开始学习,希望自己学习的过程可以帮助更多需要的人,参考网址:https://www.cnblogs.com/ysocean/p/7237499.html 1.mybatis的jar包下载地址:h ...

  10. [WC 2013]糖果公园

    Description 题库链接 给你一棵 \(n\) 个节点,有 \(m\) 种颜色的树.每个节点上有一个颜色.定义一条树上路径的价值为 \[\sum_c V_c(\sum_{i=1}^{tim_c ...