了解Keras Conv2D层中的参数数量

时间:2019-11-22 09:51:15

标签: keras conv-neural-network convolution

我的第一层是:

model.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, padding="same", activation="relu", input_shape=[32, 32, 3]))

“模型”摘要表中的参数数量:

    Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_4 (Conv2D)            (None, 32, 32, 32)        896  

据我了解,参数的数量必须为:

(No of filters) X (Number of parameters in Kernel)

即就我而言==> 32 X (3 X 3) = 288

但是它是896。896是怎么回事?

谢谢

1 个答案:

答案 0 :(得分:3)

Keras Conv2D层中的参数数量使用以下公式计算:

number_parameters = out_channels * (in_channels * kernel_h * kernel_w + 1)  # 1 for bias

所以,就您而言,

in_channels = 3
out_channels = 32
kernel_h = kernel_w = 3
number_parameters = 32(3*3*3 + 1) = 896