Keras 中的 Resnetv2 实现

Resnetv2 implementation in Keras

我想详细了解 Keras 中的 Resnetv2,即 tensorflow.keras.applications.ResNet50V2 中的那个。给定两个不同的输入大小,为什么第一个卷积层具有相同数量的参数?这是一个示例,其中输入为 440x340,输入为 550x425,每种情况下的第一层都有 9472 个参数。谢谢

_________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            [(None, 440, 340, 3) 0                                            
__________________________________________________________________________________________________
conv1_pad_Resnet50v2_classifica (None, 446, 346, 3)  0           input_1[0][0]                    
__________________________________________________________________________________________________
conv1_conv_Resnet50v2_classific (None, 220, 170, 64) 9472        conv1_pad_Resnet50v2_classificati
__________________________________________________________________________________________________


VS

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            [(None, 550, 425, 3) 0                                            
__________________________________________________________________________________________________
conv1_pad_Resnet50v2_classifica (None, 556, 431, 3)  0           input_1[0][0]                    
__________________________________________________________________________________________________
conv1_conv_Resnet50v2_classific (None, 275, 213, 64) 9472        conv1_pad_Resnet50v2_classificati
__________________________________________________________________________________________________

这是您 model.summary 中显示的前三层。 ResNet50 的源代码是 here

img_input = layers.Input(tensor=input_tensor, shape=input_shape)
x = layers.ZeroPadding2D(padding=(3, 3), name='conv1_pad')(img_input)
x = layers.Conv2D(64, (7, 7),strides=(2, 2),padding='valid',
                  kernel_initializer='he_normal',
                  name='conv1')(x)

让我们看看如何估计 Conv2D 层中的参数。

Kernel_width = 7, Kernel_height = 7, bias = 1

Num_filters_in_prev_layer = 3

Num_filters_in_current_layer =64

公式:

参数数量 = (Kernel_widthKernel_heightNum_filters_in_prev_layer +bias)*Num_filters_in_current_layer

= (7*7*3+1)*64 = 9472