tensorflow - 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
__________________________________________________________________________________________________
解决方案
这是前三层,如您的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
推荐阅读
- ruby-on-rails - URL 参数被转换为看似乱码的字符
- web-scraping - 带有 rvest 的 xpath 失败,返回一个空列表
- javascript - 使用 Jest Enzyme 测试 React Reducer
- lambda - JavaAssist 在 ASM 中是否有类似 visitInvokeDynamicInsn 的东西
- server - AllowZoneDrifting - Firewalld:它是什么,我应该禁用它吗?
- javascript - 覆盖 Firestore 中的集合
- pyspark - 如何使动态查询过滤器在 pyspark 中运行?
- sql-server - 如何在 XML SQL SERVER 中转义单引号
- c - 动态分配指针数组(K&R 练习 5-13)
- python - 需要将有关人员的信息存储在文件中并提取特定信息(python)