码迷,mamicode.com
首页 > 其他好文 > 详细

卷积神经网络---padding

时间:2018-07-14 13:13:26      阅读:506      评论:0      收藏:0      [点我收藏+]

标签:weight   channels   add   ros   dev   variable   计算   res   div   

#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]))
‘‘‘

 

卷积神经网络---padding

标签:weight   channels   add   ros   dev   variable   计算   res   div   

原文地址:https://www.cnblogs.com/cnugis/p/9309113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!