#coding:utf-8
import tensorflow as tf
tf.reset_default_graph()
image = tf.random_normal([1, 112, 96, 3])
in_channels = 3
out_channels = 32
kernel_size = 5
conv_weight = tf.Variable(tf.truncated_normal([kernel_size, kernel_size, in_channels, out_channels], stddev=0.1,
dtype=tf.float32)) print 'image shape', image.get_shape()
print 'conv weight shape', conv_weight.get_shape()
bias = tf.Variable(tf.zeros([out_channels], dtype=tf.float32))
conv = tf.nn.conv2d(image, conv_weight, strides=[1, 3, 3, 1], padding='SAME')
conv = tf.nn.bias_add(conv, bias)
print 'conv output shape with SAME padded', conv.get_shape() conv = tf.nn.conv2d(image, conv_weight, strides=[1, 3, 3, 1], padding='VALID')
conv = tf.nn.bias_add(conv, bias)
print 'conv output shape with VALID padded', conv.get_shape() '''
两种padding方式的不同
SAME 简而言之就是丢弃,像素不够的时候对那部分不进行卷积,输出图像的宽高计算公式如下(向上取整,进1):
HEIGHT = ceil(float(in_height)/float(strides[1]))
WIDTH = ceil(float(in_width)/float(strides[2])) VALID 简而言之就是补全,像素不够的时候补0,输出图像的宽高计算公式如下
HEIGHT = ceil(float(in_height - filter_height + 1)/float(strides[1]))
WIDTH = ceil(float(in_width - filter_width + 1)/float(strides[2]))
'''

打印结果

image shape (1, 112, 96, 3)
 conv weight shape (5, 5, 3, 32)
 conv output shape with SAME padded (1, 38, 32, 32)
 conv output shape with VALID padded (1, 36, 31, 32)

pool_size = 3
pool = tf.nn.max_pool(conv, ksize=[1, pool_size, pool_size, 1], strides=[1, 2, 2, 1], padding='SAME')
print pool.get_shape()
pool = tf.nn.max_pool(conv, ksize=[1, pool_size, pool_size, 1], strides=[1, 2, 2, 1], padding='VALID')
print pool.get_shape()

结果

(1, 18, 16, 32)
(1, 17, 15, 32)

#激活层
relu = tf.nn.relu(pool)
print relu.get_shape()
l2_regularizer = tf.contrib.layers.l2_regularizer(1.0)
def prelu(x, name = 'prelu'):
with tf.variable_scope(name):
alphas = tf.get_variable('alpha', x.get_shape()[-1], initializer=tf.constant_initializer(0.25), regularizer=l2_regularizer, dtype=
tf.float32)
pos = tf.nn.relu(x)
neg = tf.multiply(alphas, (x - abs(x)) * 0.5)
return pos + neg
prelu_out = prelu(pool)
print prelu_out.get_shape()

卷积神经网络---padding、 pool、 Activation layer的更多相关文章

  1. YJango的卷积神经网络——介绍

    原文地址:https://zhuanlan.zhihu.com/p/27642620 如果要提出一个新的神经网络结构,首先就需要引入像循环神经网络中“时间共享”这样的先验知识,降低学习所需要的训练数据 ...

  2. 卷积神经网络之LeNet

    开局一张图,内容全靠编. 上图引用自 [卷积神经网络-进化史]从LeNet到AlexNet. 目前常用的卷积神经网络 深度学习现在是百花齐放,各种网络结构层出不穷,计划梳理下各个常用的卷积神经网络结构 ...

  3. 简单的卷积神经网络(CNN)的搭建

    卷积神经网络(Convolutional Neural Network, CNN)是一种前馈神经网络,它的人工神经元可以响应一部分覆盖范围内的周围单元,对于大型图像处理有出色表现.与普通神经网络非常相 ...

  4. paper 162:卷积神经网络(CNN)解析

    卷积神经网络(CNN)解析: 卷积神经网络CNN解析 概揽 Layers used to build ConvNets 卷积层Convolutional layer 池化层Pooling Layer ...

  5. 第二次作业:卷积神经网络 part 1

    第二次作业:卷积神经网络 part 1 视频学习 数学基础 受结构限制严重,生成式模型效果往往不如判别式模型. RBM:数学上很漂亮,且有统计物理学支撑,但主流深度学习平台不支持RBM和预训练. 自编 ...

  6. 卷积神经网络学习笔记——Siamese networks(孪生神经网络)

    完整代码及其数据,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/DeepLearningNote 在整理这些知识点之前,我 ...

  7. 卷积神经网络学习笔记——SENet

    完整代码及其数据,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/DeepLearningNote 这里结合网络的资料和SE ...

  8. 深度学习基础-基于Numpy的卷积神经网络(CNN)实现

    本文是深度学习入门: 基于Python的实现.神经网络与深度学习(NNDL)以及动手学深度学习的读书笔记.本文将介绍基于Numpy的卷积神经网络(Convolutional Networks,CNN) ...

  9. 卷积神经网络CNN与深度学习常用框架的介绍与使用

    一.神经网络为什么比传统的分类器好 1.传统的分类器有 LR(逻辑斯特回归) 或者 linear SVM ,多用来做线性分割,假如所有的样本可以看做一个个点,如下图,有蓝色的点和绿色的点,传统的分类器 ...

随机推荐

  1. python中的__code__

    简单总结几个常用的__code__的用法: (1)func.__code__.co_argcount:返回函数的参数个数,这里的参数个数不包含*args与**kwargs,具体来讲就是*args前的参 ...

  2. spring监听器+定时任务

    背景:在原SSM项目中,拟定在每晚的23:59:59执行一个批处理任务. 设计思路:用jdk自带的定时器触发任务执行,设置下次执行间隔为24小时.定时任务由spring的监听器去启动. jdk版本:1 ...

  3. mybatis今年笔记

    1.读取配置文件:用的就是解析Xml文件的技术 2.mybatis是支持自己写dao层的,但是没有必要. mybatis做的事情: 第一个创建代理对象,第二个在代理对象中调用方法. 3.相同的注解如果 ...

  4. Profiling Top Kagglers: Bestfitting, Currently #1 in the World

    We have a new #1 on our leaderboard – a competitor who surprisingly joined the platform just two yea ...

  5. POJ 2521:How much did the businessman lose

    How much did the businessman lose Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9965 ...

  6. 1834 [ZJOI2010]network 网络扩容

    题解:先在原网络上跑最大流,然后加上带费用的边跑费用流 高一的时候做这道题怎么想不到? 注意:maxn代表的不一定是同一个变量的范围 #include<iostream> #include ...

  7. TP中统计指定字段的总数

    如统计已激活设备数量和未激活设备数量 $condition = [ ['member_id', '=', $member_id] ]; $field = [ 'COUNT(IF(active_memb ...

  8. SASS - 简介

    SASS – 简介 SASS – 环境搭建 SASS – 使用Sass程序 SASS – 语法 SASS – 变量 SASS- 局部文件(Partial) SASS – 混合(Mixin) SASS ...

  9. Android自定义View——仿滴滴出行十大司机评选活动说明

    滴滴出行原版图 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 仿图 ? ? ? ? ? ? 1.分 ...

  10. [极客大挑战 2019]Upload

    0x00 知识点 一个常规上传题目,知识点全都来自前几天写的文章: https://www.cnblogs.com/wangtanzhi/p/12243206.html 1:某些情况下绕过后缀名检测: ...