I'm trying to select the last Conv2D layer for a given (general) model. model.summary()
provides a list of layers with their type, but how can I access this to find the layer of that type?
Output from 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
I think what you are looking for is this:
layer.__class__.__name__
where layer is in
model.layers
You can iterate over model.layers
in reverse order and check layer types via isinstance
:
next(x for x in model.layers[::-1] if isinstance(x, keras.layers.Conv2D))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With