Yolo-v3微小* .weights文件包含的权重比预期的要少

时间:2019-03-27 10:20:10

标签: python tensorflow conv-neural-network yolo

我在Tensorflow中构建了一个Yolo V3 Tiny模型,我想加载Yolo本身提供的权重。我发现here并阅读了Yolo的官方代码,我可以阅读yolov3-tiny.weights丢弃前16个字节,然后读取其余字节,将它们转换为float32。

现在,yolov3-tiny.weights具有35.434.956字节,因此(35.434.956-16)/4=8.858.735 float32数字,所以我应该具有8.858.735权重。

无论如何,我的yolov3-tiny网络的摘要如下:

>>> model.summary()
Model: "model"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
Input (InputLayer)               [(None, 416, 416, 3) 0                                            
__________________________________________________________________________________________________
conv_1 (Conv2D)                 (None, 416, 416, 16) 448         Input[0][0]                       
__________________________________________________________________________________________________
norm_1 (BatchNormalizationV1)   (None, 416, 416, 16) 64          conv_1[0][0]                     
__________________________________________________________________________________________________
max_pooling2d (MaxPooling2D)    (None, 208, 208, 16) 0           norm_1[0][0]                     
__________________________________________________________________________________________________
conv_2 (Conv2D)                 (None, 208, 208, 32) 4640        max_pooling2d[0][0]              
__________________________________________________________________________________________________
norm_2 (BatchNormalizationV1)   (None, 208, 208, 32) 128         conv_2[0][0]                     
__________________________________________________________________________________________________
max_pooling2d_1 (MaxPooling2D)  (None, 104, 104, 32) 0           norm_2[0][0]                     
__________________________________________________________________________________________________
conv_3 (Conv2D)                 (None, 104, 104, 64) 18496       max_pooling2d_1[0][0]            
__________________________________________________________________________________________________
norm_3 (BatchNormalizationV1)   (None, 104, 104, 64) 256         conv_3[0][0]                     
__________________________________________________________________________________________________
max_pooling2d_2 (MaxPooling2D)  (None, 52, 52, 64)   0           norm_3[0][0]                     
__________________________________________________________________________________________________
conv_4 (Conv2D)                 (None, 52, 52, 128)  73856       max_pooling2d_2[0][0]            
__________________________________________________________________________________________________
norm_4 (BatchNormalizationV1)   (None, 52, 52, 128)  512         conv_4[0][0]                     
__________________________________________________________________________________________________
max_pooling2d_3 (MaxPooling2D)  (None, 26, 26, 128)  0           norm_4[0][0]                     
__________________________________________________________________________________________________
conv_5 (Conv2D)                 (None, 26, 26, 256)  295168      max_pooling2d_3[0][0]            
__________________________________________________________________________________________________
norm_5 (BatchNormalizationV1)   (None, 26, 26, 256)  1024        conv_5[0][0]                     
__________________________________________________________________________________________________
max_pooling2d_4 (MaxPooling2D)  (None, 13, 13, 256)  0           norm_5[0][0]                     
__________________________________________________________________________________________________
conv_6 (Conv2D)                 (None, 13, 13, 512)  1180160     max_pooling2d_4[0][0]            
__________________________________________________________________________________________________
norm_6 (BatchNormalizationV1)   (None, 13, 13, 512)  2048        conv_6[0][0]                     
__________________________________________________________________________________________________
max_pooling2d_5 (MaxPooling2D)  (None, 13, 13, 512)  0           norm_6[0][0]                     
__________________________________________________________________________________________________
conv_7 (Conv2D)                 (None, 13, 13, 1024) 4719616     max_pooling2d_5[0][0]            
__________________________________________________________________________________________________
norm_7 (BatchNormalizationV1)   (None, 13, 13, 1024) 4096        conv_7[0][0]                     
__________________________________________________________________________________________________
conv_8 (Conv2D)                 (None, 13, 13, 256)  262400      norm_7[0][0]                     
__________________________________________________________________________________________________
norm_8 (BatchNormalizationV1)   (None, 13, 13, 256)  1024        conv_8[0][0]                     
__________________________________________________________________________________________________
conv_11 (Conv2D)                (None, 13, 13, 128)  32896       norm_8[0][0]                     
__________________________________________________________________________________________________
norm_10 (BatchNormalizationV1)  (None, 13, 13, 128)  512         conv_11[0][0]                    
__________________________________________________________________________________________________
lambda_1 (Lambda)               (None, 26, 26, 128)  0           norm_10[0][0]                    
__________________________________________________________________________________________________
concatenate (Concatenate)       (None, 26, 26, 384)  0           lambda_1[0][0]                   
                                                                 norm_5[0][0]                     
__________________________________________________________________________________________________
conv_9 (Conv2D)                 (None, 13, 13, 512)  1180160     norm_8[0][0]                     
__________________________________________________________________________________________________
conv_12 (Conv2D)                (None, 26, 26, 256)  884992      concatenate[0][0]                
__________________________________________________________________________________________________
norm_9 (BatchNormalizationV1)   (None, 13, 13, 512)  2048        conv_9[0][0]                     
__________________________________________________________________________________________________
norm_11 (BatchNormalizationV1)  (None, 26, 26, 256)  1024        conv_12[0][0]                    
__________________________________________________________________________________________________
conv_10 (Conv2D)                (None, 13, 13, 255)  130815      norm_9[0][0]                     
__________________________________________________________________________________________________
conv_13 (Conv2D)                (None, 26, 26, 255)  65535       norm_11[0][0]                    
__________________________________________________________________________________________________
lambda (Lambda)                 (None, 507, 85)      0           conv_10[0][0]                    
__________________________________________________________________________________________________
lambda_2 (Lambda)               (None, 2028, 85)     0           conv_13[0][0]                    
__________________________________________________________________________________________________
concatenate_1 (Concatenate)     (None, 2535, 85)     0           lambda[0][0]                     
                                                                 lambda_2[0][0]                   
==================================================================================================
Total params: 8,861,918
Trainable params: 8,855,550
Non-trainable params: 6,368
__________________________________________________________________________________________________

,并且具有8.861.918的权重。与yolov3-tiny.weights中包含的参数相比,有(8.861.918-8.858.735)= 3183个参数更多。我在建立网络时出现任何错误还是我错过了什么?

谢谢。

1 个答案:

答案 0 :(得分:0)

对于每个具有批量归一化功能的conv layer,您都会错误地使用bias(b)。在yolo中,conv layer后跟batchnorm没有偏见。例如,对于conv_1 layer,正确的段号应该是3*3*3*16=432,而在模型中,正确的段号应该是432+16=448