gpt4 book ai didi

keras - 与 BatchNormalization 层相关的参数数量是 2048 个?

转载 作者:行者123 更新时间:2023-12-03 23:16:55 28 4
gpt4 key购买 nike

我有以下代码。

x = keras.layers.Input(batch_shape = (None, 4096))
hidden = keras.layers.Dense(512, activation = 'relu')(x)
hidden = keras.layers.BatchNormalization()(hidden)
hidden = keras.layers.Dropout(0.5)(hidden)
predictions = keras.layers.Dense(80, activation = 'sigmoid')(hidden)
mlp_model = keras.models.Model(input = [x], output = [predictions])
mlp_model.summary()

这是模型摘要:
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_3 (InputLayer) (None, 4096) 0
____________________________________________________________________________________________________
dense_1 (Dense) (None, 512) 2097664 input_3[0][0]
____________________________________________________________________________________________________
batchnormalization_1 (BatchNorma (None, 512) 2048 dense_1[0][0]
____________________________________________________________________________________________________
dropout_1 (Dropout) (None, 512) 0 batchnormalization_1[0][0]
____________________________________________________________________________________________________
dense_2 (Dense) (None, 80) 41040 dropout_1[0][0]
====================================================================================================
Total params: 2,140,752
Trainable params: 2,139,728
Non-trainable params: 1,024
____________________________________________________________________________________________________

BatchNormalization (BN) 层的输入大小为 512。根据 Keras documentation , BN 层的输出形状与输入相同,为 512。

那么BN层相关的参数个数是2048怎么办?

最佳答案

Keras 中的批量归一化实现 this paper .

正如您在那里读到的,为了在训练期间使批量归一化工作,他们需要跟踪每个归一化维度的分布。这样做,因为您在 mode=0默认情况下,他们计算上一层的每个特征 4 个参数。这些参数确保您正确传播和反向传播信息。

所以4*512 = 2048 ,这应该可以回答您的问题。

关于keras - 与 BatchNormalization 层相关的参数数量是 2048 个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42521005/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com