首页 > 解决方案 > Keras 中的 Resnetv2 实现

问题描述

我想了解有关 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
__________________________________________________________________________________________________

标签: tensorflowkerasconv-neural-networkresnet

解决方案


这是前三层,如您的model.summary. 的源代码ResNet50这里

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层中估计参数。

内核宽度 = 7,内核高度 = 7,偏差 = 1

num_filters_in_prev_layer = 3

num_filters_in_current_layer =64

公式:

参数数量 = (Kernel_width Kernel_height Num_filters_in_prev_layer +bias)*Num_filters_in_current_layer

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


推荐阅读