#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()

最新文章

  1. ES6学习笔记二
  2. js 选项卡实现
  3. IIS发布,图片和样式显示不了的问题
  4. linux查看某个端口被占用
  5. 操作符重载.xml
  6. HttpRequest Get Post,WebClient Get
  7. Objective-C消息机制的原理
  8. 旧版asp.net 发送邮件代码
  9. 在树莓派上安装leanote
  10. 关于DLL搜索路径顺序的一个问题
  11. Go语言中slice使用注意事项
  12. ROS新闻 Towards ROS-native drones 无人机支持方案
  13. 小程序ios开发注意点
  14. vim简单的移动光标
  15. mysql插入报主键冲突,解决方法主键索引重新排序
  16. 《深入理解Java虚拟机》(二)Java虚拟机运行时数据区
  17. Chap7:民间用语[《区块链中文词典》维京&甲子]
  18. Codeforces Round #322 (Div. 2) E F
  19. c++四舍五入的新方法
  20. servlet 中通过response下载文件

热门文章

  1. Mapper method 'com.xxxx.other.dao.MyDao.getNo attempted to return null from a method with a primitive return type (int)
  2. String的Split使用方法(以特定字符分隔,提取所需信息)
  3. python 将数组中取某一值的元素全部替换为其他元素的方法
  4. POJ 2521:How much did the businessman lose
  5. AVCodec 结构体
  6. Egret Engine 2D - 矢量绘图
  7. Day 1:线程与进程系列问题(一)
  8. h5-切割轮播图
  9. Q9:Palindrome Number
  10. hdu 5147 Sequence II【树状数组/线段树】