我已经为yolov3实现了很棒的软件包-
https://github.com/experiencor/keras-yolo3
现在,我想将用于训练的锚点数量从9个增加到18个,因为我读到这可以提高准确性(我不关心模型的运行时间,因此将盒子紧紧地固定在模型上非常重要此项目的对象边界)。我使用gen_anchors.py创建了18个锚,并将它们复制到config.json文件中。我还将yolo.py文件中YoloLayer定义中的锚点值加倍:
loss_yolo_1 = YoloLayer(anchors[24:],
[1*num for num in max_grid],
batch_size,
warmup_batches,
ignore_thresh,
grid_scales[0],
obj_scale,
noobj_scale,
xywh_scale,
class_scale)([input_image, pred_yolo_1, true_yolo_1, true_boxes])
loss_yolo_2 = YoloLayer(anchors[12:24],
[2*num for num in max_grid],
batch_size,
warmup_batches,
ignore_thresh,
grid_scales[1],
obj_scale,
noobj_scale,
xywh_scale,
class_scale)([input_image, pred_yolo_2, true_yolo_2, true_boxes])
loss_yolo_3 = YoloLayer(anchors[:12],
[4*num for num in max_grid],
batch_size,
warmup_batches,
ignore_thresh,
grid_scales[2],
obj_scale,
noobj_scale,
xywh_scale,
class_scale)([input_image, pred_yolo_3, true_yolo_3, true_boxes])
(原始值为12:,6:12,:6,而不是24:,12:24,:12)。我认为必须这样做是因为锚点向量的长度是两倍(如果我错了,请告诉我)。但是,现在出现此错误:
Traceback (most recent call last):
File "train.py", line 282, in
main(args)
File "train.py", line 244, in main
class_scale = config['train']['class_scale'],
File "train.py", line 131, in create_model
class_scale = class_scale
File "/home/VRC/robert.harris/keras_yolo3_tube_sub/yolo.py", line 334, in create_yolov3_model
class_scale)([input_image, pred_yolo_1, true_yolo_1, true_boxes])
File "/home/VRC/robert.harris/keras_yolo3_tube_sub/yolo.py", line 15, in init
self.anchors = tf.constant(anchors, dtype='float', shape=[1,1,1,3,2])
File "/home/VRC/robert.harris/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 207, in constant
value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/home/VRC/robert.harris/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 497, in make_tensor_proto
(shape_size, nparray.size))
ValueError: Too many elements provided. Needed at most 6, but received 12
主要是,它不喜欢此行:
self.anchors = tf.constant(anchors, dtype='float', shape=[1,1,1,3,2])
我知道张量不再只有6个值了,但是我不确定该怎么做。我试着把那条线的向量增加到 self.anchors = tf.constant(anchors,dtype ='float',shape = [1,1,1,6,2]) 这样就可以容纳12个总数,但是随后我在该区域出现错误:
pred_xy = tf.expand_dims(pred_box_xy / grid_factor, 4)
pred_wh = tf.expand_dims(tf.exp(pred_box_wh) * self.anchors / net_factor, 4)
pred_wh_half = pred_wh / 2.
pred_mins = pred_xy - pred_wh_half
pred_maxes = pred_xy + pred_wh_half
一般来说,使用9个以上锚点进行训练的正确方法是什么?谢谢!
此外,考虑到我不关心模型运行时,并且需要使框紧密适合测试集上的对象,我将对如何提高边界框的准确性提出其他建议。特别是盒子的底部(我正在尝试检测对象底部的位置)。