简体   繁体   English

(tf2/tf.keras) # params 如何在一个模型包含另一个模型时减少

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

I have a keras Model(not Layer) named Model A. Model A contains keras.Layers of types: Dense, Conv2D, AveragePooling2D, BatchNormalization, add, GlobalAveragePooling2D.我有一个名为模型 A 的 keras 模型(不是层)。模型 A 包含 keras.Layers 类型:Dense、Conv2D、AveragePooling2D、BatchNormalization、add、GlobalAveragePooling2D。

The output of model.summary() is as follows: 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
_________________________________________________________________

I have another keras model (model B) which contains model A.我有另一个 keras 模型(模型 B),其中包含模型 A。

summary():概括():

_________________________________________________________________
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
_________________________________________________________________

I wonder how could the number of total parameters in model B is less than model A?我想知道模型 B 中的总参数数量怎么会少于模型 A?

Since model B contains model A, it must be greater.由于模型 B 包含模型 A,它必须更大。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM