未验证 提交 b4578506 编写于 作者: K Kaipeng Deng 提交者: GitHub

sync TrainReader.batch to global train_batch_size (#1415)

* sync TrainReader.batch to global train_batch_size
上级 8ef9f6e6
...@@ -40,11 +40,6 @@ YOLOv3Head: ...@@ -40,11 +40,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
......
...@@ -44,7 +44,6 @@ YOLOv3Head: ...@@ -44,7 +44,6 @@ YOLOv3Head:
drop_block: true drop_block: true
YOLOv3Loss: YOLOv3Loss:
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
use_fine_grained_loss: true use_fine_grained_loss: true
......
...@@ -42,11 +42,6 @@ YOLOv3Head: ...@@ -42,11 +42,6 @@ YOLOv3Head:
drop_block: true drop_block: true
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
use_fine_grained_loss: true use_fine_grained_loss: true
......
...@@ -43,11 +43,6 @@ YOLOv3Head: ...@@ -43,11 +43,6 @@ YOLOv3Head:
keep_prob: 0.94 keep_prob: 0.94
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
use_fine_grained_loss: true use_fine_grained_loss: true
......
...@@ -41,11 +41,6 @@ YOLOv3Head: ...@@ -41,11 +41,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
use_fine_grained_loss: true use_fine_grained_loss: true
......
...@@ -44,7 +44,6 @@ YOLOv3Head: ...@@ -44,7 +44,6 @@ YOLOv3Head:
drop_block: true drop_block: true
YOLOv3Loss: YOLOv3Loss:
batch_size: 24
ignore_thresh: 0.7 ignore_thresh: 0.7
scale_x_y: 1.05 scale_x_y: 1.05
label_smooth: false label_smooth: false
......
...@@ -44,7 +44,6 @@ YOLOv3Head: ...@@ -44,7 +44,6 @@ YOLOv3Head:
drop_block: true drop_block: true
YOLOv3Loss: YOLOv3Loss:
batch_size: 24
ignore_thresh: 0.7 ignore_thresh: 0.7
scale_x_y: 1.05 scale_x_y: 1.05
label_smooth: false label_smooth: false
......
...@@ -39,7 +39,6 @@ YOLOv3Head: ...@@ -39,7 +39,6 @@ YOLOv3Head:
drop_block: true drop_block: true
YOLOv3Loss: YOLOv3Loss:
batch_size: 32
ignore_thresh: 0.7 ignore_thresh: 0.7
scale_x_y: 1.05 scale_x_y: 1.05
label_smooth: false label_smooth: false
......
...@@ -47,7 +47,6 @@ YOLOv3Head: ...@@ -47,7 +47,6 @@ YOLOv3Head:
drop_block: true drop_block: true
YOLOv3Loss: YOLOv3Loss:
batch_size: 24
ignore_thresh: 0.7 ignore_thresh: 0.7
scale_x_y: 1.05 scale_x_y: 1.05
label_smooth: false label_smooth: false
......
...@@ -35,11 +35,6 @@ YOLOv3Head: ...@@ -35,11 +35,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: true label_smooth: true
......
...@@ -36,11 +36,6 @@ YOLOv3Head: ...@@ -36,11 +36,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
......
...@@ -36,7 +36,6 @@ YOLOv3Head: ...@@ -36,7 +36,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
iou_loss: DiouLossYolo iou_loss: DiouLossYolo
......
...@@ -36,11 +36,6 @@ YOLOv3Head: ...@@ -36,11 +36,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: true label_smooth: true
......
...@@ -38,11 +38,6 @@ YOLOv3Head: ...@@ -38,11 +38,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: true label_smooth: true
......
...@@ -37,11 +37,6 @@ YOLOv3Head: ...@@ -37,11 +37,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
......
...@@ -38,11 +38,6 @@ YOLOv3Head: ...@@ -38,11 +38,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
......
...@@ -38,11 +38,6 @@ YOLOv3Head: ...@@ -38,11 +38,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: true label_smooth: true
......
...@@ -39,11 +39,6 @@ YOLOv3Head: ...@@ -39,11 +39,6 @@ YOLOv3Head:
score_threshold: 0.01 score_threshold: 0.01
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: false label_smooth: false
......
...@@ -35,11 +35,6 @@ YOLOv4Head: ...@@ -35,11 +35,6 @@ YOLOv4Head:
scale_x_y: [1.2, 1.1, 1.05] scale_x_y: [1.2, 1.1, 1.05]
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 4
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: true label_smooth: true
downsample: [8,16,32] downsample: [8,16,32]
......
...@@ -34,11 +34,6 @@ YOLOv4Head: ...@@ -34,11 +34,6 @@ YOLOv4Head:
scale_x_y: [1.2, 1.1, 1.05] scale_x_y: [1.2, 1.1, 1.05]
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 8
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: true label_smooth: true
downsample: [8,16,32] downsample: [8,16,32]
......
...@@ -34,11 +34,6 @@ YOLOv4Head: ...@@ -34,11 +34,6 @@ YOLOv4Head:
scale_x_y: [1.2, 1.1, 1.05] scale_x_y: [1.2, 1.1, 1.05]
YOLOv3Loss: YOLOv3Loss:
# batch_size here is only used for fine grained loss, not used
# for training batch_size setting, training batch_size setting
# is in configs/yolov3_reader.yml TrainReader.batch_size, batch
# size here should be set as same value as TrainReader.batch_size
batch_size: 4
ignore_thresh: 0.7 ignore_thresh: 0.7
label_smooth: true label_smooth: true
downsample: [8,16,32] downsample: [8,16,32]
......
...@@ -97,6 +97,15 @@ def load_config(file_path): ...@@ -97,6 +97,15 @@ def load_config(file_path):
del cfg[READER_KEY] del cfg[READER_KEY]
merge_config(cfg) merge_config(cfg)
# NOTE: training batch size defined only in TrainReader, sychornized
# batch size config to global, models can get batch size config
# from global config when building model.
# batch size in evaluation or inference can also be added here
if 'TrainReader' in global_config:
global_config['train_batch_size'] = global_config['TrainReader'][
'batch_size']
return global_config return global_config
......
...@@ -32,17 +32,17 @@ class YOLOv3Loss(object): ...@@ -32,17 +32,17 @@ class YOLOv3Loss(object):
Combined loss for YOLOv3 network Combined loss for YOLOv3 network
Args: Args:
batch_size (int): training batch size train_batch_size (int): training batch size
ignore_thresh (float): threshold to ignore confidence loss ignore_thresh (float): threshold to ignore confidence loss
label_smooth (bool): whether to use label smoothing label_smooth (bool): whether to use label smoothing
use_fine_grained_loss (bool): whether use fine grained YOLOv3 loss use_fine_grained_loss (bool): whether use fine grained YOLOv3 loss
instead of fluid.layers.yolov3_loss instead of fluid.layers.yolov3_loss
""" """
__inject__ = ['iou_loss', 'iou_aware_loss'] __inject__ = ['iou_loss', 'iou_aware_loss']
__shared__ = ['use_fine_grained_loss'] __shared__ = ['use_fine_grained_loss', 'train_batch_size']
def __init__(self, def __init__(self,
batch_size=8, train_batch_size=8,
ignore_thresh=0.7, ignore_thresh=0.7,
label_smooth=True, label_smooth=True,
use_fine_grained_loss=False, use_fine_grained_loss=False,
...@@ -51,7 +51,7 @@ class YOLOv3Loss(object): ...@@ -51,7 +51,7 @@ class YOLOv3Loss(object):
downsample=[32, 16, 8], downsample=[32, 16, 8],
scale_x_y=1., scale_x_y=1.,
match_score=False): match_score=False):
self._batch_size = batch_size self._train_batch_size = train_batch_size
self._ignore_thresh = ignore_thresh self._ignore_thresh = ignore_thresh
self._label_smooth = label_smooth self._label_smooth = label_smooth
self._use_fine_grained_loss = use_fine_grained_loss self._use_fine_grained_loss = use_fine_grained_loss
...@@ -65,7 +65,7 @@ class YOLOv3Loss(object): ...@@ -65,7 +65,7 @@ class YOLOv3Loss(object):
anchor_masks, mask_anchors, num_classes, prefix_name): anchor_masks, mask_anchors, num_classes, prefix_name):
if self._use_fine_grained_loss: if self._use_fine_grained_loss:
return self._get_fine_grained_loss( return self._get_fine_grained_loss(
outputs, targets, gt_box, self._batch_size, num_classes, outputs, targets, gt_box, self._train_batch_size, num_classes,
mask_anchors, self._ignore_thresh) mask_anchors, self._ignore_thresh)
else: else:
losses = [] losses = []
...@@ -95,7 +95,7 @@ class YOLOv3Loss(object): ...@@ -95,7 +95,7 @@ class YOLOv3Loss(object):
outputs, outputs,
targets, targets,
gt_box, gt_box,
batch_size, train_batch_size,
num_classes, num_classes,
mask_anchors, mask_anchors,
ignore_thresh, ignore_thresh,
...@@ -108,7 +108,7 @@ class YOLOv3Loss(object): ...@@ -108,7 +108,7 @@ class YOLOv3Loss(object):
targets ([Variables]): List of Variables, The targets for yolo targets ([Variables]): List of Variables, The targets for yolo
loss calculatation. loss calculatation.
gt_box (Variable): The ground-truth boudding boxes. gt_box (Variable): The ground-truth boudding boxes.
batch_size (int): The training batch size train_batch_size (int): The training batch size
num_classes (int): class num of dataset num_classes (int): class num of dataset
mask_anchors ([[float]]): list of anchors in each output layer mask_anchors ([[float]]): list of anchors in each output layer
ignore_thresh (float): prediction bbox overlap any gt_box greater ignore_thresh (float): prediction bbox overlap any gt_box greater
...@@ -171,7 +171,7 @@ class YOLOv3Loss(object): ...@@ -171,7 +171,7 @@ class YOLOv3Loss(object):
loss_h = fluid.layers.reduce_sum(loss_h, dim=[1, 2, 3]) loss_h = fluid.layers.reduce_sum(loss_h, dim=[1, 2, 3])
if self._iou_loss is not None: if self._iou_loss is not None:
loss_iou = self._iou_loss(x, y, w, h, tx, ty, tw, th, anchors, loss_iou = self._iou_loss(x, y, w, h, tx, ty, tw, th, anchors,
downsample, self._batch_size, downsample, self._train_batch_size,
scale_x_y) scale_x_y)
loss_iou = loss_iou * tscale_tobj loss_iou = loss_iou * tscale_tobj
loss_iou = fluid.layers.reduce_sum(loss_iou, dim=[1, 2, 3]) loss_iou = fluid.layers.reduce_sum(loss_iou, dim=[1, 2, 3])
...@@ -180,14 +180,14 @@ class YOLOv3Loss(object): ...@@ -180,14 +180,14 @@ class YOLOv3Loss(object):
if self._iou_aware_loss is not None: if self._iou_aware_loss is not None:
loss_iou_aware = self._iou_aware_loss( loss_iou_aware = self._iou_aware_loss(
ioup, x, y, w, h, tx, ty, tw, th, anchors, downsample, ioup, x, y, w, h, tx, ty, tw, th, anchors, downsample,
self._batch_size, scale_x_y) self._train_batch_size, scale_x_y)
loss_iou_aware = loss_iou_aware * tobj loss_iou_aware = loss_iou_aware * tobj
loss_iou_aware = fluid.layers.reduce_sum( loss_iou_aware = fluid.layers.reduce_sum(
loss_iou_aware, dim=[1, 2, 3]) loss_iou_aware, dim=[1, 2, 3])
loss_iou_awares.append(fluid.layers.reduce_mean(loss_iou_aware)) loss_iou_awares.append(fluid.layers.reduce_mean(loss_iou_aware))
loss_obj_pos, loss_obj_neg = self._calc_obj_loss( loss_obj_pos, loss_obj_neg = self._calc_obj_loss(
output, obj, tobj, gt_box, self._batch_size, anchors, output, obj, tobj, gt_box, self._train_batch_size, anchors,
num_classes, downsample, self._ignore_thresh, scale_x_y) num_classes, downsample, self._ignore_thresh, scale_x_y)
loss_cls = fluid.layers.sigmoid_cross_entropy_with_logits(cls, tcls) loss_cls = fluid.layers.sigmoid_cross_entropy_with_logits(cls, tcls)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册