保姆级 Keras 实现 YOLO v3 一
- 一. YOLO v3 总览
- 二. 特征提取网络
- 特征提取网络代码实现
- 三. 特征融合
- 特征融合代码实现
- 四. 网络输出
- 模型输出代码实现
- 五. 网络模型代码实现
如果要给 YOLO 目标检测算法一个评价的话, 就是快和准, 现在已经到了 v8, 但是我为什么还要写 v3 呢? 我觉得 v3 是一个节点, 承上启下的节点. 它有 v1 和 v2 的影子, 也为后面的其他版本奠定了基础. 对于教学或者学习 YOLO 是极好的
一. YOLO v3 总览
如果要给 YOLO v3 一个学习的策略的话, 我觉得从整体到局部比较合适, 我们把 YOLO v3 总结如下
相比于祥细的结构图, 这样的三个框就把 YOLO v3 概括完了. 后面我们再将各个部分拆开祥细说明, 这就是从整体到局部的策略
二. 特征提取网络
这是最容易实现的部分, 因为不会涉及到坐标计算与损失函数之类的东西, 只需要按结构用代码实现即可, 下面是结构图, 括号里面的数字是各方块输出的 shape
这个也不是祥细的结构图, 祥细的结构图还需要将各个方块展开, 前面的数字是 n 个这样的 Block 重复, 现在把 Conv Block 展开如下
Residual Block 展开如下
特征图的尺寸是输入图像的 1 32 1 \over 32 321, 但是并没有用我们常见的 Pooling 来减小特征图尺寸, 而是使用步长为 2 的卷积层来实现的, 就是各个 Residual Block 之前的 Conv2D 层
Conv2D(kernel_size = (3, 3), strides = (2, 2), padding = "same")
特征提取网络代码实现
因为结构有重复性, 所以可以定义一个函数来重复调用
# 定义 cbl (Conv2D, BatchNormalization, LeakyReLU) 函数
def cbl(inputs, filters, kernel_size):x = keras.layers.Conv2D(filters = filters, kernel_size = kernel_size, strides = (1, 1),padding = "valid" if (1, 1) == kernel_size else "same")(inputs)x = keras.layers.BatchNormalization()(x)x = keras.layers.LeakyReLU(alpha = 0.1)(x)return x
接下来定义 Residual Block
# 定义 residual_block 函数
# filters: 第一个 cbl 的卷积核数量, 第二个 cbl 卷积核数量自动乘 2
# repeats: 模块重复次数
def residual_block(inputs, filters, repeats):x = inputsfor i in range(repeats):x = cbl(x, filters, kernel_size = (1, 1))x = cbl(x, filters * 2, kernel_size = (3, 3))x = keras.layers.Add()([inputs, x])return x
有了这两个函数, 就可以定义完整的特征提取网络 darknet
# 定义 darn_net 函数
def dark_net(inputs = None):x = cbl(inputs, filters = 32, kernel_size = (3, 3))x = keras.layers.Conv2D(filters = 64, kernel_size = (3, 3), strides = (2, 2), padding = "same")(x)x = residual_block(x, filters = 32, repeats = 1)x = keras.layers.Conv2D(filters = 128, kernel_size = (3, 3), strides = (2, 2), padding = "same")(x)x = residual_block(x, filters = 64, repeats = 2)x = keras.layers.Conv2D(filters = 256, kernel_size = (3, 3), strides = (2, 2), padding = "same")(x)# 52 × 52 特征图x_52 = residual_block(x, filters = 128, repeats = 8)x = keras.layers.Conv2D(filters = 512, kernel_size = (3, 3), strides = (2, 2), padding = "same")(x_52)# 26 × 26 特征图x_26 = residual_block(x, filters = 256, repeats = 8)x = keras.layers.Conv2D(filters = 1024, kernel_size = (3, 3), strides = (2, 2), padding = "same")(x_26)# 13 × 13 特征图x_13 = residual_block(x, filters = 512, repeats = 4)return x_13, x_26, x_52
这样就和前面的结构图对上了, 函数输出 x_13, x_26, x_52 三层, 后面特征融合的时候会用到
三. 特征融合
这个也没有什么大问题, 只需要将上面的 13 × 13 特征图上采样放大与 26 × 26 特征图在最后一个维度拼接, 26 × 26 特征图上采样放大与 52 × 52 特征图在最后一个维度拼接, 如下图
特征融合代码实现
特征融合 Conv Block 部分也有很多重复的方块, 所以可以定义成一个函数方便调用
# 定义 cbl block 函数
# filters: 第一个 block 的卷积核数量, 其他会自动计算
def cbl_block(inputs, filters):x = cbl(inputs, filters, kernel_size = (1, 1))x = cbl(x, filters * 2, kernel_size = (3, 3))x = cbl(x, filters, kernel_size = (1, 1))x = cbl(x, filters * 2, kernel_size = (3, 3))x = cbl(x, filters, kernel_size = (1, 1))return x
总的特征融合函数如下
# 定义 neck 函数
def neck(inputs = None):x_13, x_26, x_52 = inputsfeature = cbl_block(x_13, 512)feature = cbl(feature, filters = 256, kernel_size = (1, 1))feature = keras.layers.UpSampling2D(size = (2, 2), interpolation = "bilinear")(feature)feature = keras.layers.Concatenate(axis = -1)([feature, x_26])x_26 = cbl_block(feature, 256)feature = cbl(x_26, filters = 128, kernel_size = (1, 1))feature = keras.layers.UpSampling2D(size = (2, 2), interpolation = "bilinear")(feature)feature = keras.layers.Concatenate(axis = -1)([feature, x_52])x_52 = cbl_block(feature, 128)return x_13, x_26, x_52
四. 网络输出
这部分就更简单了, 将融合后的特征图做卷积, 变换到对应的通道数, 因为我要训练的数据集是 VOC2007, 所以输出通道数为 75 = (4 + 1 + 20) × 3. 模型结构如下
模型输出代码实现
输出函数如下, 输入是三个融合后的特征图
# 定义 head 函数
def head(inputs, filters):x_13, x_26, x_52 = inputsx_13 = cbl(x_13, 1024, kernel_size = (3, 3))x_13 = cbl(x_13, filters, kernel_size = (1, 1))x_26 = cbl(x_26, 512, kernel_size = (3, 3))x_26 = cbl(x_26, filters, kernel_size = (1, 1))x_52 = cbl(x_52, 256, kernel_size = (3, 3))x_52 = cbl(x_52, filters, kernel_size = (1, 1))return x_13, x_26, x_52
五. 网络模型代码实现
有了上面的相应的函数之后, 定义完整的模型就变得很简单了, 由 dark_net, neck, head 三部分构成
# 模型定义
image = keras.layers.Input(shape = (416, 416, 3), name = "input")x_13, x_26, x_52 = dark_net(inputs = image)
x_13, x_26, x_52 = neck([x_13, x_26, x_52])
x_13, x_26, x_52 = head([x_13, x_26, x_52], filters = 75)model = keras.Model(inputs = image,outputs = [x_13, x_26, x_52],name = "yolov3")
model.summary()
Model: "yolov3"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input (InputLayer) [(None, 416, 416, 3) 0
__________________________________________________________________________________________________
conv2d (Conv2D) (None, 416, 416, 32) 896 input[0][0]
__________________________________________________________________________________________________
batch_normalization (BatchNorma (None, 416, 416, 32) 128 conv2d[0][0]
__________________________________________________________________________________________________
leaky_re_lu (LeakyReLU) (None, 416, 416, 32) 0 batch_normalization[0][0]
__________________________________________________________________________________________________
conv2d_1 (Conv2D) (None, 208, 208, 64) 18496 leaky_re_lu[0][0]
__________________________________________________________________________________________________
conv2d_2 (Conv2D) (None, 208, 208, 32) 2080 conv2d_1[0][0]
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, 208, 208, 32) 128 conv2d_2[0][0]
__________________________________________________________________________________________________
leaky_re_lu_1 (LeakyReLU) (None, 208, 208, 32) 0 batch_normalization_1[0][0]
__________________________________________________________________________________________________
conv2d_3 (Conv2D) (None, 208, 208, 64) 18496 leaky_re_lu_1[0][0]
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, 208, 208, 64) 256 conv2d_3[0][0]
__________________________________________________________________________________________________
leaky_re_lu_2 (LeakyReLU) (None, 208, 208, 64) 0 batch_normalization_2[0][0]
__________________________________________________________________________________________________
add (Add) (None, 208, 208, 64) 0 conv2d_1[0][0] leaky_re_lu_2[0][0]
__________________________________________________________________________________________________
conv2d_4 (Conv2D) (None, 104, 104, 128 73856 add[0][0]
__________________________________________________________________________________________________
conv2d_5 (Conv2D) (None, 104, 104, 64) 8256 conv2d_4[0][0]
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, 104, 104, 64) 256 conv2d_5[0][0]
__________________________________________________________________________________________________
leaky_re_lu_3 (LeakyReLU) (None, 104, 104, 64) 0 batch_normalization_3[0][0]
__________________________________________________________________________________________________
conv2d_6 (Conv2D) (None, 104, 104, 128 73856 leaky_re_lu_3[0][0]
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, 104, 104, 128 512 conv2d_6[0][0]
__________________________________________________________________________________________________
leaky_re_lu_4 (LeakyReLU) (None, 104, 104, 128 0 batch_normalization_4[0][0]
__________________________________________________________________________________________________
add_1 (Add) (None, 104, 104, 128 0 conv2d_4[0][0] leaky_re_lu_4[0][0]
__________________________________________________________________________________________________
conv2d_7 (Conv2D) (None, 104, 104, 64) 8256 add_1[0][0]
__________________________________________________________________________________________________
batch_normalization_5 (BatchNor (None, 104, 104, 64) 256 conv2d_7[0][0]
__________________________________________________________________________________________________
leaky_re_lu_5 (LeakyReLU) (None, 104, 104, 64) 0 batch_normalization_5[0][0]
__________________________________________________________________________________________________
conv2d_8 (Conv2D) (None, 104, 104, 128 73856 leaky_re_lu_5[0][0]
__________________________________________________________________________________________________
batch_normalization_6 (BatchNor (None, 104, 104, 128 512 conv2d_8[0][0]
__________________________________________________________________________________________________
leaky_re_lu_6 (LeakyReLU) (None, 104, 104, 128 0 batch_normalization_6[0][0]
__________________________________________________________________________________________________
add_2 (Add) (None, 104, 104, 128 0 conv2d_4[0][0] leaky_re_lu_6[0][0]
__________________________________________________________________________________________________
conv2d_9 (Conv2D) (None, 52, 52, 256) 295168 add_2[0][0]
__________________________________________________________________________________________________
conv2d_10 (Conv2D) (None, 52, 52, 128) 32896 conv2d_9[0][0]
__________________________________________________________________________________________________
batch_normalization_7 (BatchNor (None, 52, 52, 128) 512 conv2d_10[0][0]
__________________________________________________________________________________________________
leaky_re_lu_7 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_7[0][0]
__________________________________________________________________________________________________
conv2d_11 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_7[0][0]
__________________________________________________________________________________________________
batch_normalization_8 (BatchNor (None, 52, 52, 256) 1024 conv2d_11[0][0]
__________________________________________________________________________________________________
leaky_re_lu_8 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_8[0][0]
__________________________________________________________________________________________________
add_3 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_8[0][0]
__________________________________________________________________________________________________
conv2d_12 (Conv2D) (None, 52, 52, 128) 32896 add_3[0][0]
__________________________________________________________________________________________________
batch_normalization_9 (BatchNor (None, 52, 52, 128) 512 conv2d_12[0][0]
__________________________________________________________________________________________________
leaky_re_lu_9 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_9[0][0]
__________________________________________________________________________________________________
conv2d_13 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_9[0][0]
__________________________________________________________________________________________________
batch_normalization_10 (BatchNo (None, 52, 52, 256) 1024 conv2d_13[0][0]
__________________________________________________________________________________________________
leaky_re_lu_10 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_10[0][0]
__________________________________________________________________________________________________
add_4 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_10[0][0]
__________________________________________________________________________________________________
conv2d_14 (Conv2D) (None, 52, 52, 128) 32896 add_4[0][0]
__________________________________________________________________________________________________
batch_normalization_11 (BatchNo (None, 52, 52, 128) 512 conv2d_14[0][0]
__________________________________________________________________________________________________
leaky_re_lu_11 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_11[0][0]
__________________________________________________________________________________________________
conv2d_15 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_11[0][0]
__________________________________________________________________________________________________
batch_normalization_12 (BatchNo (None, 52, 52, 256) 1024 conv2d_15[0][0]
__________________________________________________________________________________________________
leaky_re_lu_12 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_12[0][0]
__________________________________________________________________________________________________
add_5 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_12[0][0]
__________________________________________________________________________________________________
conv2d_16 (Conv2D) (None, 52, 52, 128) 32896 add_5[0][0]
__________________________________________________________________________________________________
batch_normalization_13 (BatchNo (None, 52, 52, 128) 512 conv2d_16[0][0]
__________________________________________________________________________________________________
leaky_re_lu_13 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_13[0][0]
__________________________________________________________________________________________________
conv2d_17 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_13[0][0]
__________________________________________________________________________________________________
batch_normalization_14 (BatchNo (None, 52, 52, 256) 1024 conv2d_17[0][0]
__________________________________________________________________________________________________
leaky_re_lu_14 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_14[0][0]
__________________________________________________________________________________________________
add_6 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_14[0][0]
__________________________________________________________________________________________________
conv2d_18 (Conv2D) (None, 52, 52, 128) 32896 add_6[0][0]
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 52, 52, 128) 512 conv2d_18[0][0]
__________________________________________________________________________________________________
leaky_re_lu_15 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_15[0][0]
__________________________________________________________________________________________________
conv2d_19 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_15[0][0]
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 52, 52, 256) 1024 conv2d_19[0][0]
__________________________________________________________________________________________________
leaky_re_lu_16 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_16[0][0]
__________________________________________________________________________________________________
add_7 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_16[0][0]
__________________________________________________________________________________________________
conv2d_20 (Conv2D) (None, 52, 52, 128) 32896 add_7[0][0]
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 52, 52, 128) 512 conv2d_20[0][0]
__________________________________________________________________________________________________
leaky_re_lu_17 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_17[0][0]
__________________________________________________________________________________________________
conv2d_21 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_17[0][0]
__________________________________________________________________________________________________
batch_normalization_18 (BatchNo (None, 52, 52, 256) 1024 conv2d_21[0][0]
__________________________________________________________________________________________________
leaky_re_lu_18 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_18[0][0]
__________________________________________________________________________________________________
add_8 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_18[0][0]
__________________________________________________________________________________________________
conv2d_22 (Conv2D) (None, 52, 52, 128) 32896 add_8[0][0]
__________________________________________________________________________________________________
batch_normalization_19 (BatchNo (None, 52, 52, 128) 512 conv2d_22[0][0]
__________________________________________________________________________________________________
leaky_re_lu_19 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_19[0][0]
__________________________________________________________________________________________________
conv2d_23 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_19[0][0]
__________________________________________________________________________________________________
batch_normalization_20 (BatchNo (None, 52, 52, 256) 1024 conv2d_23[0][0]
__________________________________________________________________________________________________
leaky_re_lu_20 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_20[0][0]
__________________________________________________________________________________________________
add_9 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_20[0][0]
__________________________________________________________________________________________________
conv2d_24 (Conv2D) (None, 52, 52, 128) 32896 add_9[0][0]
__________________________________________________________________________________________________
batch_normalization_21 (BatchNo (None, 52, 52, 128) 512 conv2d_24[0][0]
__________________________________________________________________________________________________
leaky_re_lu_21 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_21[0][0]
__________________________________________________________________________________________________
conv2d_25 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_21[0][0]
__________________________________________________________________________________________________
batch_normalization_22 (BatchNo (None, 52, 52, 256) 1024 conv2d_25[0][0]
__________________________________________________________________________________________________
leaky_re_lu_22 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_22[0][0]
__________________________________________________________________________________________________
add_10 (Add) (None, 52, 52, 256) 0 conv2d_9[0][0] leaky_re_lu_22[0][0]
__________________________________________________________________________________________________
conv2d_26 (Conv2D) (None, 26, 26, 512) 1180160 add_10[0][0]
__________________________________________________________________________________________________
conv2d_27 (Conv2D) (None, 26, 26, 256) 131328 conv2d_26[0][0]
__________________________________________________________________________________________________
batch_normalization_23 (BatchNo (None, 26, 26, 256) 1024 conv2d_27[0][0]
__________________________________________________________________________________________________
leaky_re_lu_23 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_23[0][0]
__________________________________________________________________________________________________
conv2d_28 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_23[0][0]
__________________________________________________________________________________________________
batch_normalization_24 (BatchNo (None, 26, 26, 512) 2048 conv2d_28[0][0]
__________________________________________________________________________________________________
leaky_re_lu_24 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_24[0][0]
__________________________________________________________________________________________________
add_11 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_24[0][0]
__________________________________________________________________________________________________
conv2d_29 (Conv2D) (None, 26, 26, 256) 131328 add_11[0][0]
__________________________________________________________________________________________________
batch_normalization_25 (BatchNo (None, 26, 26, 256) 1024 conv2d_29[0][0]
__________________________________________________________________________________________________
leaky_re_lu_25 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_25[0][0]
__________________________________________________________________________________________________
conv2d_30 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_25[0][0]
__________________________________________________________________________________________________
batch_normalization_26 (BatchNo (None, 26, 26, 512) 2048 conv2d_30[0][0]
__________________________________________________________________________________________________
leaky_re_lu_26 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_26[0][0]
__________________________________________________________________________________________________
add_12 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_26[0][0]
__________________________________________________________________________________________________
conv2d_31 (Conv2D) (None, 26, 26, 256) 131328 add_12[0][0]
__________________________________________________________________________________________________
batch_normalization_27 (BatchNo (None, 26, 26, 256) 1024 conv2d_31[0][0]
__________________________________________________________________________________________________
leaky_re_lu_27 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_27[0][0]
__________________________________________________________________________________________________
conv2d_32 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_27[0][0]
__________________________________________________________________________________________________
batch_normalization_28 (BatchNo (None, 26, 26, 512) 2048 conv2d_32[0][0]
__________________________________________________________________________________________________
leaky_re_lu_28 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_28[0][0]
__________________________________________________________________________________________________
add_13 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_28[0][0]
__________________________________________________________________________________________________
conv2d_33 (Conv2D) (None, 26, 26, 256) 131328 add_13[0][0]
__________________________________________________________________________________________________
batch_normalization_29 (BatchNo (None, 26, 26, 256) 1024 conv2d_33[0][0]
__________________________________________________________________________________________________
leaky_re_lu_29 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_29[0][0]
__________________________________________________________________________________________________
conv2d_34 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_29[0][0]
__________________________________________________________________________________________________
batch_normalization_30 (BatchNo (None, 26, 26, 512) 2048 conv2d_34[0][0]
__________________________________________________________________________________________________
leaky_re_lu_30 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_30[0][0]
__________________________________________________________________________________________________
add_14 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_30[0][0]
__________________________________________________________________________________________________
conv2d_35 (Conv2D) (None, 26, 26, 256) 131328 add_14[0][0]
__________________________________________________________________________________________________
batch_normalization_31 (BatchNo (None, 26, 26, 256) 1024 conv2d_35[0][0]
__________________________________________________________________________________________________
leaky_re_lu_31 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_31[0][0]
__________________________________________________________________________________________________
conv2d_36 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_31[0][0]
__________________________________________________________________________________________________
batch_normalization_32 (BatchNo (None, 26, 26, 512) 2048 conv2d_36[0][0]
__________________________________________________________________________________________________
leaky_re_lu_32 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_32[0][0]
__________________________________________________________________________________________________
add_15 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_32[0][0]
__________________________________________________________________________________________________
conv2d_37 (Conv2D) (None, 26, 26, 256) 131328 add_15[0][0]
__________________________________________________________________________________________________
batch_normalization_33 (BatchNo (None, 26, 26, 256) 1024 conv2d_37[0][0]
__________________________________________________________________________________________________
leaky_re_lu_33 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_33[0][0]
__________________________________________________________________________________________________
conv2d_38 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_33[0][0]
__________________________________________________________________________________________________
batch_normalization_34 (BatchNo (None, 26, 26, 512) 2048 conv2d_38[0][0]
__________________________________________________________________________________________________
leaky_re_lu_34 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_34[0][0]
__________________________________________________________________________________________________
add_16 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_34[0][0]
__________________________________________________________________________________________________
conv2d_39 (Conv2D) (None, 26, 26, 256) 131328 add_16[0][0]
__________________________________________________________________________________________________
batch_normalization_35 (BatchNo (None, 26, 26, 256) 1024 conv2d_39[0][0]
__________________________________________________________________________________________________
leaky_re_lu_35 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_35[0][0]
__________________________________________________________________________________________________
conv2d_40 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_35[0][0]
__________________________________________________________________________________________________
batch_normalization_36 (BatchNo (None, 26, 26, 512) 2048 conv2d_40[0][0]
__________________________________________________________________________________________________
leaky_re_lu_36 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_36[0][0]
__________________________________________________________________________________________________
add_17 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_36[0][0]
__________________________________________________________________________________________________
conv2d_41 (Conv2D) (None, 26, 26, 256) 131328 add_17[0][0]
__________________________________________________________________________________________________
batch_normalization_37 (BatchNo (None, 26, 26, 256) 1024 conv2d_41[0][0]
__________________________________________________________________________________________________
leaky_re_lu_37 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_37[0][0]
__________________________________________________________________________________________________
conv2d_42 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_37[0][0]
__________________________________________________________________________________________________
batch_normalization_38 (BatchNo (None, 26, 26, 512) 2048 conv2d_42[0][0]
__________________________________________________________________________________________________
leaky_re_lu_38 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_38[0][0]
__________________________________________________________________________________________________
add_18 (Add) (None, 26, 26, 512) 0 conv2d_26[0][0] leaky_re_lu_38[0][0]
__________________________________________________________________________________________________
conv2d_43 (Conv2D) (None, 13, 13, 1024) 4719616 add_18[0][0]
__________________________________________________________________________________________________
conv2d_44 (Conv2D) (None, 13, 13, 512) 524800 conv2d_43[0][0]
__________________________________________________________________________________________________
batch_normalization_39 (BatchNo (None, 13, 13, 512) 2048 conv2d_44[0][0]
__________________________________________________________________________________________________
leaky_re_lu_39 (LeakyReLU) (None, 13, 13, 512) 0 batch_normalization_39[0][0]
__________________________________________________________________________________________________
conv2d_45 (Conv2D) (None, 13, 13, 1024) 4719616 leaky_re_lu_39[0][0]
__________________________________________________________________________________________________
batch_normalization_40 (BatchNo (None, 13, 13, 1024) 4096 conv2d_45[0][0]
__________________________________________________________________________________________________
leaky_re_lu_40 (LeakyReLU) (None, 13, 13, 1024) 0 batch_normalization_40[0][0]
__________________________________________________________________________________________________
add_19 (Add) (None, 13, 13, 1024) 0 conv2d_43[0][0] leaky_re_lu_40[0][0]
__________________________________________________________________________________________________
conv2d_46 (Conv2D) (None, 13, 13, 512) 524800 add_19[0][0]
__________________________________________________________________________________________________
batch_normalization_41 (BatchNo (None, 13, 13, 512) 2048 conv2d_46[0][0]
__________________________________________________________________________________________________
leaky_re_lu_41 (LeakyReLU) (None, 13, 13, 512) 0 batch_normalization_41[0][0]
__________________________________________________________________________________________________
conv2d_47 (Conv2D) (None, 13, 13, 1024) 4719616 leaky_re_lu_41[0][0]
__________________________________________________________________________________________________
batch_normalization_42 (BatchNo (None, 13, 13, 1024) 4096 conv2d_47[0][0]
__________________________________________________________________________________________________
leaky_re_lu_42 (LeakyReLU) (None, 13, 13, 1024) 0 batch_normalization_42[0][0]
__________________________________________________________________________________________________
add_20 (Add) (None, 13, 13, 1024) 0 conv2d_43[0][0] leaky_re_lu_42[0][0]
__________________________________________________________________________________________________
conv2d_48 (Conv2D) (None, 13, 13, 512) 524800 add_20[0][0]
__________________________________________________________________________________________________
batch_normalization_43 (BatchNo (None, 13, 13, 512) 2048 conv2d_48[0][0]
__________________________________________________________________________________________________
leaky_re_lu_43 (LeakyReLU) (None, 13, 13, 512) 0 batch_normalization_43[0][0]
__________________________________________________________________________________________________
conv2d_49 (Conv2D) (None, 13, 13, 1024) 4719616 leaky_re_lu_43[0][0]
__________________________________________________________________________________________________
batch_normalization_44 (BatchNo (None, 13, 13, 1024) 4096 conv2d_49[0][0]
__________________________________________________________________________________________________
leaky_re_lu_44 (LeakyReLU) (None, 13, 13, 1024) 0 batch_normalization_44[0][0]
__________________________________________________________________________________________________
add_21 (Add) (None, 13, 13, 1024) 0 conv2d_43[0][0] leaky_re_lu_44[0][0]
__________________________________________________________________________________________________
conv2d_50 (Conv2D) (None, 13, 13, 512) 524800 add_21[0][0]
__________________________________________________________________________________________________
batch_normalization_45 (BatchNo (None, 13, 13, 512) 2048 conv2d_50[0][0]
__________________________________________________________________________________________________
leaky_re_lu_45 (LeakyReLU) (None, 13, 13, 512) 0 batch_normalization_45[0][0]
__________________________________________________________________________________________________
conv2d_51 (Conv2D) (None, 13, 13, 1024) 4719616 leaky_re_lu_45[0][0]
__________________________________________________________________________________________________
batch_normalization_46 (BatchNo (None, 13, 13, 1024) 4096 conv2d_51[0][0]
__________________________________________________________________________________________________
leaky_re_lu_46 (LeakyReLU) (None, 13, 13, 1024) 0 batch_normalization_46[0][0]
__________________________________________________________________________________________________
add_22 (Add) (None, 13, 13, 1024) 0 conv2d_43[0][0] leaky_re_lu_46[0][0]
__________________________________________________________________________________________________
conv2d_52 (Conv2D) (None, 13, 13, 512) 524800 add_22[0][0]
__________________________________________________________________________________________________
batch_normalization_47 (BatchNo (None, 13, 13, 512) 2048 conv2d_52[0][0]
__________________________________________________________________________________________________
leaky_re_lu_47 (LeakyReLU) (None, 13, 13, 512) 0 batch_normalization_47[0][0]
__________________________________________________________________________________________________
conv2d_53 (Conv2D) (None, 13, 13, 1024) 4719616 leaky_re_lu_47[0][0]
__________________________________________________________________________________________________
batch_normalization_48 (BatchNo (None, 13, 13, 1024) 4096 conv2d_53[0][0]
__________________________________________________________________________________________________
leaky_re_lu_48 (LeakyReLU) (None, 13, 13, 1024) 0 batch_normalization_48[0][0]
__________________________________________________________________________________________________
conv2d_54 (Conv2D) (None, 13, 13, 512) 524800 leaky_re_lu_48[0][0]
__________________________________________________________________________________________________
batch_normalization_49 (BatchNo (None, 13, 13, 512) 2048 conv2d_54[0][0]
__________________________________________________________________________________________________
leaky_re_lu_49 (LeakyReLU) (None, 13, 13, 512) 0 batch_normalization_49[0][0]
__________________________________________________________________________________________________
conv2d_55 (Conv2D) (None, 13, 13, 1024) 4719616 leaky_re_lu_49[0][0]
__________________________________________________________________________________________________
batch_normalization_50 (BatchNo (None, 13, 13, 1024) 4096 conv2d_55[0][0]
__________________________________________________________________________________________________
leaky_re_lu_50 (LeakyReLU) (None, 13, 13, 1024) 0 batch_normalization_50[0][0]
__________________________________________________________________________________________________
conv2d_56 (Conv2D) (None, 13, 13, 512) 524800 leaky_re_lu_50[0][0]
__________________________________________________________________________________________________
batch_normalization_51 (BatchNo (None, 13, 13, 512) 2048 conv2d_56[0][0]
__________________________________________________________________________________________________
leaky_re_lu_51 (LeakyReLU) (None, 13, 13, 512) 0 batch_normalization_51[0][0]
__________________________________________________________________________________________________
conv2d_57 (Conv2D) (None, 13, 13, 256) 131328 leaky_re_lu_51[0][0]
__________________________________________________________________________________________________
batch_normalization_52 (BatchNo (None, 13, 13, 256) 1024 conv2d_57[0][0]
__________________________________________________________________________________________________
leaky_re_lu_52 (LeakyReLU) (None, 13, 13, 256) 0 batch_normalization_52[0][0]
__________________________________________________________________________________________________
up_sampling2d (UpSampling2D) (None, 26, 26, 256) 0 leaky_re_lu_52[0][0]
__________________________________________________________________________________________________
concatenate (Concatenate) (None, 26, 26, 768) 0 up_sampling2d[0][0] add_18[0][0]
__________________________________________________________________________________________________
conv2d_58 (Conv2D) (None, 26, 26, 256) 196864 concatenate[0][0]
__________________________________________________________________________________________________
batch_normalization_53 (BatchNo (None, 26, 26, 256) 1024 conv2d_58[0][0]
__________________________________________________________________________________________________
leaky_re_lu_53 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_53[0][0]
__________________________________________________________________________________________________
conv2d_59 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_53[0][0]
__________________________________________________________________________________________________
batch_normalization_54 (BatchNo (None, 26, 26, 512) 2048 conv2d_59[0][0]
__________________________________________________________________________________________________
leaky_re_lu_54 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_54[0][0]
__________________________________________________________________________________________________
conv2d_60 (Conv2D) (None, 26, 26, 256) 131328 leaky_re_lu_54[0][0]
__________________________________________________________________________________________________
batch_normalization_55 (BatchNo (None, 26, 26, 256) 1024 conv2d_60[0][0]
__________________________________________________________________________________________________
leaky_re_lu_55 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_55[0][0]
__________________________________________________________________________________________________
conv2d_61 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_55[0][0]
__________________________________________________________________________________________________
batch_normalization_56 (BatchNo (None, 26, 26, 512) 2048 conv2d_61[0][0]
__________________________________________________________________________________________________
leaky_re_lu_56 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_56[0][0]
__________________________________________________________________________________________________
conv2d_62 (Conv2D) (None, 26, 26, 256) 131328 leaky_re_lu_56[0][0]
__________________________________________________________________________________________________
batch_normalization_57 (BatchNo (None, 26, 26, 256) 1024 conv2d_62[0][0]
__________________________________________________________________________________________________
leaky_re_lu_57 (LeakyReLU) (None, 26, 26, 256) 0 batch_normalization_57[0][0]
__________________________________________________________________________________________________
conv2d_63 (Conv2D) (None, 26, 26, 128) 32896 leaky_re_lu_57[0][0]
__________________________________________________________________________________________________
batch_normalization_58 (BatchNo (None, 26, 26, 128) 512 conv2d_63[0][0]
__________________________________________________________________________________________________
leaky_re_lu_58 (LeakyReLU) (None, 26, 26, 128) 0 batch_normalization_58[0][0]
__________________________________________________________________________________________________
up_sampling2d_1 (UpSampling2D) (None, 52, 52, 128) 0 leaky_re_lu_58[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 52, 52, 384) 0 up_sampling2d_1[0][0] add_10[0][0]
__________________________________________________________________________________________________
conv2d_64 (Conv2D) (None, 52, 52, 128) 49280 concatenate_1[0][0]
__________________________________________________________________________________________________
batch_normalization_59 (BatchNo (None, 52, 52, 128) 512 conv2d_64[0][0]
__________________________________________________________________________________________________
leaky_re_lu_59 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_59[0][0]
__________________________________________________________________________________________________
conv2d_65 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_59[0][0]
__________________________________________________________________________________________________
batch_normalization_60 (BatchNo (None, 52, 52, 256) 1024 conv2d_65[0][0]
__________________________________________________________________________________________________
leaky_re_lu_60 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_60[0][0]
__________________________________________________________________________________________________
conv2d_66 (Conv2D) (None, 52, 52, 128) 32896 leaky_re_lu_60[0][0]
__________________________________________________________________________________________________
batch_normalization_61 (BatchNo (None, 52, 52, 128) 512 conv2d_66[0][0]
__________________________________________________________________________________________________
leaky_re_lu_61 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_61[0][0]
__________________________________________________________________________________________________
conv2d_67 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_61[0][0]
__________________________________________________________________________________________________
batch_normalization_62 (BatchNo (None, 52, 52, 256) 1024 conv2d_67[0][0]
__________________________________________________________________________________________________
leaky_re_lu_62 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_62[0][0]
__________________________________________________________________________________________________
conv2d_68 (Conv2D) (None, 52, 52, 128) 32896 leaky_re_lu_62[0][0]
__________________________________________________________________________________________________
batch_normalization_63 (BatchNo (None, 52, 52, 128) 512 conv2d_68[0][0]
__________________________________________________________________________________________________
leaky_re_lu_63 (LeakyReLU) (None, 52, 52, 128) 0 batch_normalization_63[0][0]
__________________________________________________________________________________________________
conv2d_69 (Conv2D) (None, 13, 13, 1024) 9438208 add_22[0][0]
__________________________________________________________________________________________________
conv2d_71 (Conv2D) (None, 26, 26, 512) 1180160 leaky_re_lu_57[0][0]
__________________________________________________________________________________________________
conv2d_73 (Conv2D) (None, 52, 52, 256) 295168 leaky_re_lu_63[0][0]
__________________________________________________________________________________________________
batch_normalization_64 (BatchNo (None, 13, 13, 1024) 4096 conv2d_69[0][0]
__________________________________________________________________________________________________
batch_normalization_66 (BatchNo (None, 26, 26, 512) 2048 conv2d_71[0][0]
__________________________________________________________________________________________________
batch_normalization_68 (BatchNo (None, 52, 52, 256) 1024 conv2d_73[0][0]
__________________________________________________________________________________________________
leaky_re_lu_64 (LeakyReLU) (None, 13, 13, 1024) 0 batch_normalization_64[0][0]
__________________________________________________________________________________________________
leaky_re_lu_66 (LeakyReLU) (None, 26, 26, 512) 0 batch_normalization_66[0][0]
__________________________________________________________________________________________________
leaky_re_lu_68 (LeakyReLU) (None, 52, 52, 256) 0 batch_normalization_68[0][0]
__________________________________________________________________________________________________
conv2d_70 (Conv2D) (None, 13, 13, 75) 76875 leaky_re_lu_64[0][0]
__________________________________________________________________________________________________
conv2d_72 (Conv2D) (None, 26, 26, 75) 38475 leaky_re_lu_66[0][0]
__________________________________________________________________________________________________
conv2d_74 (Conv2D) (None, 52, 52, 75) 19275 leaky_re_lu_68[0][0]
__________________________________________________________________________________________________
batch_normalization_65 (BatchNo (None, 13, 13, 75) 300 conv2d_70[0][0]
__________________________________________________________________________________________________
batch_normalization_67 (BatchNo (None, 26, 26, 75) 300 conv2d_72[0][0]
__________________________________________________________________________________________________
batch_normalization_69 (BatchNo (None, 52, 52, 75) 300 conv2d_74[0][0]
__________________________________________________________________________________________________
leaky_re_lu_65 (LeakyReLU) (None, 13, 13, 75) 0 batch_normalization_65[0][0]
__________________________________________________________________________________________________
leaky_re_lu_67 (LeakyReLU) (None, 26, 26, 75) 0 batch_normalization_67[0][0]
__________________________________________________________________________________________________
leaky_re_lu_69 (LeakyReLU) (None, 52, 52, 75) 0 batch_normalization_69[0][0]
==================================================================================================
Total params: 66,416,517
Trainable params: 66,367,427
Non-trainable params: 49,090
__________________________________________________________________________________________________
加上输入层一共 243 层
下一篇: 保姆级 Keras 实现 YOLO v3 二