我正在尝试为给定(通用)模型选择最后一个 Conv2D 层。model.summary()提供了一个图层列表及其类型,但如何访问它以找到该类型的图层?
输出model.summary():
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 224, 224, 3) 0
_________________________________________________________________
block1_conv1 (Conv2D) (None, 224, 224, 64) 1792
_________________________________________________________________
...
_________________________________________________________________
predictions (Dense) (None, 1000) 4097000
=================================================================
Total params: 138,357,544
Trainable params: 138,357,544
Non-trainable params: 0
Run Code Online (Sandbox Code Playgroud)
您可以按model.layers相反顺序迭代并通过以下方式检查图层类型isinstance:
next(x for x in model.layers[::-1] if isinstance(x, keras.layers.Conv2D))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3197 次 |
| 最近记录: |