首页 文章

混淆了CNN中卷积层的输出

提问于
浏览
0

我正在实现卷积神经网络,但我对张量流中卷积层的输出大小感到困惑,所以我看到这个规则是为了计算卷积的输出,即(Size - Filter 2P)/ Stride 1所以如果我们有一个sie 256 x 256灰度的图像,即channel = 1,滤波器大小为11,zerro-padding = 0,stride = 2.然后根据该规则,通过替换 . 输出将是(256 - 11)/ 2 1 = 123.5,即= 123 x 123 . 但实际上通过在tensorflow中实现相同的值,同时打印出结果,我看到,输出是128 x 128 !!怎么会发生?

更新

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)

1 回答

  • 1

    在行中使用填充VALID:

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

    padding 'SAME'表示保留相同的输入大小,填充'VALID'表示计算公式 ( Size - Filter + 2P)/ Stride +1 并输出有效数字 .

相关问题