0
votes

I am using keras' pretrained resnet 101 v2 CNN model. I wanted to know what the size of the filter was. I tried checking my model's summary but it doesn't really tell me the size directly. is it a 2x2x2 matrix or a 3x3x3 or something else? The snippet of the model summary is:

Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_3 (InputLayer)            [(None, 255, 255, 3) 0                                            
__________________________________________________________________________________________________
conv1_pad (ZeroPadding2D)       (None, 261, 261, 3)  0           input_3[0][0]                    
__________________________________________________________________________________________________
conv1_conv (Conv2D)             (None, 128, 128, 64) 9472        conv1_pad[0][0]                  
__________________________________________________________________________________________________
pool1_pad (ZeroPadding2D)       (None, 130, 130, 64) 0           conv1_conv[0][0]                 
__________________________________________________________________________________________________
pool1_pool (MaxPooling2D)       (None, 64, 64, 64)   0           pool1_pad[0][0]                  
__________________________________________________________________________________________________
conv2_block1_preact_bn (BatchNo (None, 64, 64, 64)   256         pool1_pool[0][0]                 
__________________________________________________________________________________________________
conv2_block1_preact_relu (Activ (None, 64, 64, 64)   0           conv2_block1_preact_bn[0][0]     
__________________________________________________________________________________________________
conv2_block1_1_conv (Conv2D)    (None, 64, 64, 64)   4096        conv2_block1_preact_relu[0][0]   
__________________________________________________________________________________________________
conv2_block1_1_bn (BatchNormali (None, 64, 64, 64)   256         conv2_block1_1_conv[0][0]        
__________________________________________________________________________________________________
conv2_block1_1_relu (Activation (None, 64, 64, 64)   0           conv2_block1_1_bn[0][0]          
__________________________________________________________________________________________________
conv2_block1_2_pad (ZeroPadding (None, 66, 66, 64)   0           conv2_block1_1_relu[0][0]        
__________________________________________________________________________________________________
conv2_block1_2_conv (Conv2D)    (None, 64, 64, 64)   36864       conv2_block1_2_pad[0][0]         
__________________________________________________________________________________________________
conv2_block1_2_bn (BatchNormali (None, 64, 64, 64)   256         conv2_block1_2_conv[0][0]        
__________________________________________________________________________________________________
conv2_block1_2_relu (Activation (None, 64, 64, 64)   0           conv2_block1_2_bn[0][0]          
__________________________________________________________________________________________________
conv2_block1_0_conv (Conv2D)    (None, 64, 64, 256)  16640       conv2_block1_preact_relu[0][0]   
__________________________________________________________________________________________________
conv2_block1_3_conv (Conv2D)    (None, 64, 64, 256)  16640       conv2_block1_2_relu[0][0]      
1

1 Answers

0
votes

I am not sure if there is a predefined method to get this. It should be possible to get filter shape, count for a layer this way for a certain layer,

print(model.layers[2].name)
print(model.layers[2].weights[0].shape)

This gives output,

conv1_conv
(7, 7, 3, 64)

Printing print(model.layers[2].weights) gives something like,

conv1_conv
[<tf.Variable 'conv1_conv/kernel:0' shape=(7, 7, 3, 64) dtype=float32, numpy=
array([[[[ 2.04881709e-02,  1.74432080e-02, -1.19661177e-02, ...,
...

To get details for all the layers,

for i, layer in enumerate(model.layers):
  print(layer.name)
  if layer.weights:
    print(layer.weights[0].shape)
    print(layer.weights[1].shape)
  print('-' * 30)

Partial output,

input_3
------------------------------
conv1_pad
------------------------------
conv1_conv
(7, 7, 3, 64)
(64,)
------------------------------
conv1_bn
(64,)
(64,)
------------------------------
conv1_relu
------------------------------
pool1_pad
------------------------------
pool1_pool
------------------------------
conv2_block1_1_conv
(1, 1, 64, 64)
(64,)
------------------------------
conv2_block1_1_bn
(64,)
(64,)
------------------------------
conv2_block1_1_relu
------------------------------
conv2_block1_2_conv
(3, 3, 64, 64)
(64,)
------------------------------