TensorFlow学习笔记(1)——conv2d函数的padding参数详解
来源:互联网 发布:学directx编程要多久 编辑:程序博客网 时间:2024/06/05 17:20
conv2d函数原型:
tf.nn.conv2d ( input, filter, strides, padding, use_cudnn_on_gpu=None, name=None )
参数说明:
input:输入图像,shape为 [ batch, in_height, in_width, in_channels ],例如 [ 1, 28, 28, 1 ]
filter:卷积核,shape为 [ filter_height, filter_width, in_channels, out_channels ],例如 [ 5, 5, 1, 1 ]
strides:步长,一维向量,长度为 4,例如 [ 1, 1, 1, 1 ]
padding:string类型,取值为‘SAME’或‘VALID’,例如‘SAME’
第一种padding方式:‘SAME’
1、卷积后的Feature map尺寸的计算方式为:
out_height = ceil ( float ( in_height ) / float ( strides [1] ) )
out_width = ceil ( float ( in_width ) / float ( strides [2] ) )
2、例子:
import tensorflow as tf
x_image = tf.Variable ( tf.random_normal ( [ 1, 28, 28, 1] ) )
kernel = tf.Variable ( tf.random_normal ( [5, 5, 1, 1] ) )
conv = tf.nn.conv2d ( x_image, kernel, strides= [ 1, 1, 1, 1 ], padding='SAME' )
with tf.Session () as sess:
sess.run ( tf.global_variables_initializer () )
result = ( sess.run ( conv ) )
print ( result.shape )
程序运行结果:
====== RESTART: D:\Python_code\ML\test.py ======
( 1, 28, 28, 1 )
>>>
3、经过卷积后的Feature map尺寸的计算方式说明:
out_height = ceil ( float ( in_height ) / float ( strides[1] ) ) = ceil ( float ( 28 ) / float ( 1 ) ) = 28
out_width = ceil ( float ( in_width ) / float ( strides[2] ) ) = ceil ( float ( 28 ) / float ( 1 ) ) = 28
第二种padding方式:‘VALID’
1、卷积后的Feature map尺寸的计算方式为:
out_height = ceil ( float ( in_height - filter_height + 1 ) / float ( strides[1] ) )
out_width = ceil ( float ( in_width - filter_width + 1 ) / float ( strides[2] ) )
2、例子:
import tensorflow as tf
x_image = tf.Variable ( tf.random_normal ( [ 1, 28, 28, 1] ) )
kernel = tf.Variable ( tf.random_normal ( [5, 5, 1, 1] ) )
conv = tf.nn.conv2d ( x_image, kernel, strides= [ 1, 1, 1, 1 ], padding='VALID' )
with tf.Session () as sess:
sess.run ( tf.global_variables_initializer () )
result = ( sess.run ( conv ) )
print ( result.shape )
程序运行结果:
====== RESTART: D:\Python_code\ML\test.py ======
( 1, 24, 24, 1 )
>>>
3、经过卷积后的Feature map尺寸的计算方式说明:
out_height = ceil ( float (i n_height - filter_height + 1 ) / float ( strides[1] ) ) = ceil ( float ( 28 - 5+ 1 ) / float ( 1 ) ) = 24
out_width = ceil ( float ( in_width - filter_width + 1 ) / float ( strides[2] ) ) = ceil ( float ( 28 - 5+ 1 ) / float ( 1 ) ) = 24
- TensorFlow学习笔记(1)——conv2d函数的padding参数详解
- tensorflow学习基础篇1——conv2d 函数说明
- tensorflow conv2d的padding解释以及参数解释
- tensorflow conv2d的padding解释以及参数解释
- tensorflow conv2d的padding解释以及参数解释
- tensorflow conv2d的padding解释以及参数解释
- [TensorFlow 学习笔记-04]卷积函数之tf.nn.conv2d
- Tensorflow系列——conv2d的用法
- Tensorflow -- tf.nn.conv2d() 函数详解
- [Tensor] tf.nn.conv2d函数中的padding参数
- tensorflow conv2d()参数解析
- tensorflow `conv2d max_pool 方法参数
- TensorFlow学习笔记(三):tf.nn.conv2d是怎样实现卷积的?
- TensorFlow学习笔记(3)——softmax_cross_entropy_with_logits函数详解
- TensorFlow学习笔记(十七)tf.nn.conv2d
- TensorFlow-tf.nn.conv2d 函数
- tensorflow conv2d padding,tf图像卷积边缘扩展问题
- tensorflow学习:tf.nn.conv2d 和 tf.layers.conv2d
- HTML表单
- JBOSS基本安装以及端口的修改
- 剑指Offer-11.数值的整数次方
- IAR 使用小技巧--持续更新
- 24.session聚合统计之重构实现思路与重构session聚合
- TensorFlow学习笔记(1)——conv2d函数的padding参数详解
- C++只在栈或堆上实例化对象
- Android6.0以上权限相关Util
- myeclipse2014如何添加源码反编译工具插件
- ZigBee 用IO口模拟I2C驱动程序
- nginx 中的 rewrite 和 try_files
- MyEclipse配置Tomcat7
- django入门笔记
- 图解插入排序--直接插入排序