- 有效填充
- 边缘填充
>>> import tensorflow as tf >>> aa = tf.truncated_normal([100,11,11,3]) >>> aa.shape TensorShape([Dimension(100), Dimension(11), Dimension(11), Dimension(3)]) >>> bb = tf.layers.conv2d(aa, 3, 4, 2,padding='same') >>> bb.shape TensorShape([Dimension(100), Dimension(6), Dimension(6), Dimension(3)])
>>> import tensorflow as tf >>> aa = tf.truncated_normal([100,11,11,3]) >>> aa.shape TensorShape([Dimension(100), Dimension(11), Dimension(11), Dimension(3)]) >>> bb = tf.layers.conv2d(aa, 3, 4, 3,padding='same') >>> bb.shape TensorShape([Dimension(100), Dimension(4), Dimension(4), Dimension(3)])
>>> bb = tf.layers.conv2d(aa, 3, 4, (2,3),padding='same') >>> bb.shape TensorShape([Dimension(100), Dimension(6), Dimension(4), Dimension(3)])
>>> import tensorflow as tf >>> aa = tf.truncated_normal([100,11,11,3]) #创建形状为11*11*3的tensor(前面的100为batch size,可忽略) >>> bb = tf.layers.conv2d(aa, 3, 4, 1,padding='valid') #strides设为1 >>> bb.shape TensorShape([Dimension(100), Dimension(8), Dimension(8), Dimension(3)]) #输出大小为 8*8*3 >>> bb = tf.layers.conv2d(aa, 3, 3, 1,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(9), Dimension(9), Dimension(3)])
当strides设为k时,则输出的特征图的大小为【(input_height - kernel_size + 1)/k, (input_width - kernel_size + 1)/k, output_depth】
注意:除法向上取整
>>> bb = tf.layers.conv2d(aa, 3, 4, 2,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(4), Dimension(4), Dimension(3)]) >>> bb = tf.layers.conv2d(aa, 3, 4, 3,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(3), Dimension(3), Dimension(3)]) >>> bb = tf.layers.conv2d(aa, 3, 4, 4,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(2), Dimension(2), Dimension(3)])
以下几个可以验证上述结论:
>>> bb = tf.layers.conv2d(aa, 3, 3, 2,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(5), Dimension(5), Dimension(3)]) >>> bb = tf.layers.conv2d(aa, 3, 3, 3,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(3), Dimension(3), Dimension(3)]) >>> bb = tf.layers.conv2d(aa, 3, 3, 4,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(3), Dimension(3), Dimension(3)]) >>> bb = tf.layers.conv2d(aa, 3, 3, 5,padding='valid') >>> bb.shape TensorShape([Dimension(100), Dimension(2), Dimension(2), Dimension(3)])
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:卷积操作特征图输出大小 - Python技术站