我从互联网上下载了下面的节目
def my_model(input_shape):
# Define the input placeholder as a tensor with shape input_shape. Think of this as your input image!
X_input = Input(input_shape)
# Zero-Padding: pads the border of X_input with zeroes
X = ZeroPadding2D((3, 3))(X_input)
# CONV -> BN -> RELU Block applied to X
X = Conv2D(32, (7, 7), strides = (1, 1), name = 'conv0')(X)
X = BatchNormalization(axis = 3, name = 'bn0')(X)
X = Activation('relu')(X)
# MAXPOOL
X = MaxPooling2D((2, 2), name='max_pool')(X)
# FLATTEN X (means convert it to a vector) + FULLYCONNECTED
X = Flatten()(X)
X = Dense(1, activation='sigmoid', name='fc')(X)
# Create model. This creates your Keras model instance, you'll use this instance to train/test the model.
model = Model(inputs = X_input, outputs = X, name='myModel')
return model
mymodel = my_model((64,64,3))
mymodel.summary()摘要的输出如下所示
Layer (type) Output Shape Param #
=================================================================
input_3 (InputLayer) (None, 64, 64, 3) 0
_________________________________________________________________
zero_padding2d_3 (ZeroPaddin (None, 70, 70, 3) 0
_________________________________________________________________
conv0 (Conv2D) (None, 64, 64, 32) 4736
_________________________________________________________________
bn0 (BatchNormalization) (None, 64, 64, 32) 128
_________________________________________________________________
activation_2 (Activation) (None, 64, 64, 32) 0
_________________________________________________________________
max_pool (MaxPooling2D) (None, 32, 32, 32) 0
_________________________________________________________________
flatten_2 (Flatten) (None, 32768) 0
_________________________________________________________________
fc (Dense) (None, 1) 32769
=================================================================
Total params: 37,633
Trainable params: 37,569
Non-trainable params: 64我的问题是,这个不可训练的对角是从哪一层采取的,即64。另一个问题是批处理规范化如何具有参数128?
请求您的帮助,我们如何从上面定义的模型中得到上述数字。谢谢你的时间和帮助。
发布于 2019-08-28 12:59:33
BatchNormalization层由[gamma weights, beta weights, moving_mean(non-trainable), moving_variance(non-trainable)]组成,对于每个参数,最后一个轴中的每个元素都有一个值(默认为keras,但如果愿意,可以更改轴)。
在您的代码中,在BatchNormalization层之前的最后一个维度中的大小为32,因此32*4=128参数和由于有2不可训练的参数,所以有32*2=64不可存储的参数。
https://stackoverflow.com/questions/57692323
复制相似问题