tensorflow中conv和max_pool参数的理解

conv参数理解

res = tf.nn.conv2d(
input_x, 
W, 
strides=[batch_stride, input_height_stride, input_width_stride, channel_stride], 
padding='SAME' or 'VALID')
  1. input_x的各维度解释:[batch_count, each_x_height, each_x_width, channel_count]
  2. W的各维度解释:比input_x的各维度少了第1维batch_count
  3. strides:convolution的步幅
  4. padding:2个值,
  • 'SAME': 卷积后的输出的height和width和input_x的一样,是通过在边沿padding 0值来实现的
  • 'VALID': 不Padding,只卷积有效的部分

max_pool

示例

>>> x_29 = tf.Variable(tf.random_normal([1, 29, 29, 1]))
>>> sess.run(tf.global_variables_initializer())
>>> res=tf.nn.max_pool(x_29, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1],padding='SAME')
>>> sess.run(res)

>>> res.shape
TensorShape([Dimension(1), Dimension(15), Dimension(15), Dimension(1)])
>>> res=tf.nn.max_pool(x_29, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1],padding='VALID')
>>> sess.run(res)

>>> res.shape
TensorShape([Dimension(1), Dimension(14), Dimension(14), Dimension(1)])
>>> 

结论:

看看padding='SAME'和'VALID'的区别,结论是和conv一样的:'VALID'是不进行padding,‘SAME'时,在根据stride和ksize到最后一步边沿max_pool的时候,是否需要padding 0来进行有效求max。

其他参数:

1.ksize和strides的4个值,分别对应x_29的每个维度,通常来说,第一个和最后一个的batch_count和channel_count都是1, 为了用到所有数据;而中间的width和height用来缩小输入,ksize和strides的这2个值一样,为了不忽略所有像素。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容