(tf2/tf.keras) 当一个模型包含另一个模型时,#params 怎么会减少

(tf2/tf.keras) How could # params decreases when a model contains another model

我有一个名为模型 A 的 keras 模型(不是图层)。模型 A 包含 keras.Layers 类型:Dense、Conv2D、AveragePooling2D、BatchNormalization、add、GlobalAveragePooling2D。

model.summary()的输出结果如下:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
layer_type_1 (Layer_type_1)  multiple                  3776      
_________________________________________________________________
...                           ...                      ...
_________________________________________________________________
dense (Dense)                multiple                  1024      
=================================================================
Total params: 4,787,808
Trainable params: 4,782,496
Non-trainable params: 5,312
_________________________________________________________________

我有另一个 keras 模型(模型 B),其中 包含 模型 A。

摘要():

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d (Conv2D)              multiple                  35        
_________________________________________________________________
model_A (ModelA)             multiple                  4787232   
=================================================================
Total params: 4,787,267
Trainable params: 4,781,955
Non-trainable params: 5,312
_________________________________________________________________

我想知道模型 B 的总参数数量怎么会比模型 A

由于模型 B 包含模型 A,因此它必须更大。

我发现这是因为模型 B 中的第一个 Conv2D 层导致输入形状(到模型 A)从 (W, D, 6) 更改为 (W, D, 5)。