卷积神经网络---padding

匿名 (未验证) 提交于 2019-12-03 00:41:02
#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])) ‘‘‘

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!