简体   繁体   English

对CNN中卷积层的输出感到困惑

[英]confused about the output of convolutional layer in CNN

I am implementing convolutional neural network, but i am confused about the output size of convolution layer in tensorflow, so I have seen this rule in order to calculate the output of convolution, that is ( Size - Filter + 2P)/ Stride +1 so if we have an image of sie 256 x 256 gray-scale ie channel = 1 with filter size 11 and zerro-padding = 0 and stride = 2. Then according to that rule, by substitution. 我正在实现卷积神经网络,但是我对张量流中卷积层的输出大小感到困惑,所以我已经看到了此规则以便计算卷积的输出,即(Size-Filter + 2P)/ Stride +1所以如果我们有一个sie 256 x 256灰度图像,即channel = 1,滤镜大小为11,zerro-padding = 0,stride = 2,则根据该规则进行替换。 The output will be (256 - 11)/2 + 1 = 123.5 ie = 123 x 123 . 输出将是(256-11)/ 2 + 1 = 123.5即= 123 x 123。 But actually by implementing the same values in tensorflow, while printed out the result, I have seen, that the output is 128 x 128 !! 但是实际上,通过在张量流中实现相同的值,同时打印出结果,我已经看到,输出为128 x 128! how is that happen ? 那是怎么回事?

update 更新

IMAGE_H = 256
IMAGE_W = 256
batch_size = 10
num_hidden = 64
num_channels = 1
depth = 32

input = tf.placeholder(
     tf.float32, shape=(batch_size, IMAGE_H, IMAGE_W, num_channels))

w1 = tf.Variable(tf.random_normal([11, 11, num_channels,depth],stddev=0.1))
w2 = tf.Variable(tf.random_normal([7, 7, depth, depth], stddev=0.1))

b1 = tf.Variable(tf.zeros([depth]))
b2 = tf.Variable(tf.constant(1.0, shape=[depth]))

....
# model

conv1 = tf.nn.conv2d(input, w1 , [1, 2, 2, 1], padding='SAME')
print('conv1', conv1)
hidden_1 = tf.nn.relu(conv1 + b1)  

Use padding VALID in line: 在行中使用填充有效值:

conv1 = tf.nn.conv2d(input, w1 , [1, 2, 2, 1], padding='VALID')

padding 'SAME' means that preserve the same input size, and padding 'VALID' means that calculate the formula ( Size - Filter + 2P)/ Stride +1 and give a valid number to output. padding'SAME'表示保留相同的输入大小,padding'VALID'表示计算公式( Size - Filter + 2P)/ Stride +1并给出有效数字以进行输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM