第二个卷积层参数个数是否正确?

Is the number of second convolution layer parameters correct?

我有简单的 CNN 解决 MNIST 数据问题。

cnn_model = tf.keras.Sequential([
    tf.keras.layers.Conv2D(filters=24, kernel_size=(3,3), activation='relu'), 
    tf.keras.layers.Conv2D(filters=36, kernel_size=(3,3), activation='relu'),
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(128, activation=tf.nn.relu),
    tf.keras.layers.Dense(10, activation='softmax')
])

这是摘要的样子:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_12 (Conv2D)           (None, 26, 26, 24)        240       
_________________________________________________________________
conv2d_13 (Conv2D)           (None, 24, 24, 36)        7812      
_________________________________________________________________
flatten_13 (Flatten)         (None, 20736)             0         
_________________________________________________________________
dense_26 (Dense)             (None, 128)               2654336   
_________________________________________________________________
dense_27 (Dense)             (None, 10)                1290      
=================================================================
Total params: 2,663,678
Trainable params: 2,663,678
Non-trainable params: 0
_________________________________________________________________

为了问题的简单性,我跳过了问题中的池层。

第一个卷积层有240个参数,很容易计算:(kernel size + bias) * filters数量:(3*3+1)*24。 请解释为什么第二个卷积层有 7812 个参数(36 * 217)。

flatten层的大小为20736,也就是上一层的36个filter产生的像素数:24 * 24 * 36。

但是我们如何从上一层的24张图像中通过36个过滤器得到36张图像呢?展平层的大小不应该是 36 * 24 * 24 * 24 也就是上一层的过滤器数量 * 上一层的位图大小 * 第一个卷积层的过滤器数量吗?

一个卷积层的参数个数是

(filter_height * filter_width * in_channels * out_channels) + out_channels

你的情况是

(3 * 3 * 24 * 36) + 36 = 7,812

这种卷积的输出形状是

(n_samples, remaining_height, remaining_width, n_filters)