计划做一个图片检测的模型训练,但是数据集只有图片的分类标签,没有特征的bounding box,准备用预训练的YOLO3模型提取图片的bounding box,然后对提取结果进行筛选,制作完整的图片检测数据集。
keras版本的代码下载地址:https://github.com/qqwweee/keras-yolo3
Yolo官网地址:https://pjreddie.com/darknet/yolo/
第一步:在github上下载YOLO3的代码,代码用的是keras框架,而YOLO官网是使用darknet训练的,模型保存在yolov3.weight,为了在keras框架中使用YOLO3模型,首先需要将模型权重文件转换为.h5格式的文件,github上提供了转换代码convert.py和转换指令:
python convert.py yolov3.cfg yolov3.weights model_data/yolo.h5
问题:执行后报错:TypeError: buffer is too small for requested array
Parsing section convolutional_1
conv2d bn leaky (3, 3, 32, 64)
Parsing section convolutional_2
conv2d bn leaky (1, 1, 64, 32)
Parsing section convolutional_3
conv2d bn leaky (3, 3, 32, 64)
Parsing section shortcut_0
Parsing section convolutional_4
conv2d bn leaky (3, 3, 64, 128)
Parsing section convolutional_5
conv2d bn leaky (1, 1, 128, 64)
Parsing section convolutional_6
conv2d bn leaky (3, 3, 64, 128)
Parsing section shortcut_1
Parsing section convolutional_7
conv2d bn leaky (1, 1, 128, 64)
Parsing section convolutional_8
conv2d bn leaky (3, 3, 64, 128)
Parsing section shortcut_2
Parsing section convolutional_9
conv2d bn leaky (3, 3, 128, 256)
Traceback (most recent call last):
File "convert.py", line 263, in <module>
_main(parser.parse_args())
File "convert.py", line 144, in _main
buffer=weights_file.read(weights_size * 4))
TypeError: buffer is too small for requested array
解决:在网上找了一些方法,试了之后没有解决,我的文件转换了一部分之后停止了,说明前半部分转换正常,后半本分有问题了,查看了一下我的yolov3.weights文件,发现只有2.3M,而官网的文件有200多M,重新下载了权重文件,再次运行指令就正常了。(这只是我遇到的一种解决方案,如果没解决可以看看github,有很多类似的问题)
外网下载较慢,我这里分享一个百度网盘的链接供大家使用:
https://pan.baidu.com/s/1bMzehqJD2R6u9S0jmi3dsg 密码: e16k
运行效果:
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) (None, None, None, 3 0
__________________________________________________________________________________________________
conv2d_1 (Conv2D) (None, None, None, 3 864 input_1[0][0]
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, None, None, 3 128 conv2d_1[0][0]
__________________________________________________________________________________________________
leaky_re_lu_1 (LeakyReLU) (None, None, None, 3 0 batch_normalization_1[0][0]
__________________________________________________________________________________________________
zero_padding2d_1 (ZeroPadding2D (None, None, None, 3 0 leaky_re_lu_1[0][0]
__________________________________________________________________________________________________
conv2d_2 (Conv2D) (None, None, None, 6 18432 zero_padding2d_1[0][0]
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, None, None, 6 256 conv2d_2[0][0]
__________________________________________________________________________________________________
leaky_re_lu_2 (LeakyReLU) (None, None, None, 6 0 batch_normalization_2[0][0]
__________________________________________________________________________________________________
conv2d_3 (Conv2D) (None, None, None, 3 2048 leaky_re_lu_2[0][0]
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, None, None, 3 128 conv2d_3[0][0]
__________________________________________________________________________________________________
leaky_re_lu_3 (LeakyReLU) (None, None, None, 3 0 batch_normalization_3[0][0]
__________________________________________________________________________________________________
conv2d_4 (Conv2D) (None, None, None, 6 18432 leaky_re_lu_3[0][0]
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, None, None, 6 256 conv2d_4[0][0]
__________________________________________________________________________________________________
leaky_re_lu_4 (LeakyReLU) (None, None, None, 6 0 batch_normalization_4[0][0]
__________________________________________________________________________________________________
add_1 (Add) (None, None, None, 6 0 leaky_re_lu_2[0][0]
leaky_re_lu_4[0][0]
__________________________________________________________________________________________________