diff --git a/configs/dcn/yolov3_r50vd_dcn.yml b/configs/dcn/yolov3_r50vd_dcn.yml index 0493597b1c804f4b842242dd419278cab51548e2..99815fc324fc2e7b2a23dcef045901469b7341b6 100755 --- a/configs/dcn/yolov3_r50vd_dcn.yml +++ b/configs/dcn/yolov3_r50vd_dcn.yml @@ -40,11 +40,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: false diff --git a/configs/dcn/yolov3_r50vd_dcn_db_iouaware_obj365_pretrained_coco.yml b/configs/dcn/yolov3_r50vd_dcn_db_iouaware_obj365_pretrained_coco.yml index 6177aaac7f26dd0c6395a040cddfa11ffc705d39..63c4cad4eeeb32cddc09f5ada7732551b0ca0301 100755 --- a/configs/dcn/yolov3_r50vd_dcn_db_iouaware_obj365_pretrained_coco.yml +++ b/configs/dcn/yolov3_r50vd_dcn_db_iouaware_obj365_pretrained_coco.yml @@ -44,7 +44,6 @@ YOLOv3Head: drop_block: true YOLOv3Loss: - batch_size: 8 ignore_thresh: 0.7 label_smooth: false use_fine_grained_loss: true diff --git a/configs/dcn/yolov3_r50vd_dcn_db_iouloss_obj365_pretrained_coco.yml b/configs/dcn/yolov3_r50vd_dcn_db_iouloss_obj365_pretrained_coco.yml index 5e943145330c49b30c1742169a101018187f654c..037c52714b91723e39bc0a3aba6a1daeb745c7f5 100755 --- a/configs/dcn/yolov3_r50vd_dcn_db_iouloss_obj365_pretrained_coco.yml +++ b/configs/dcn/yolov3_r50vd_dcn_db_iouloss_obj365_pretrained_coco.yml @@ -42,11 +42,6 @@ YOLOv3Head: drop_block: true 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 label_smooth: false use_fine_grained_loss: true diff --git a/configs/dcn/yolov3_r50vd_dcn_db_obj365_pretrained_coco.yml b/configs/dcn/yolov3_r50vd_dcn_db_obj365_pretrained_coco.yml index 3c69e410a303212df3539c261465a8cd02e7911c..084930b96d78abb7cc8b7e2b503008ea52b41cf6 100755 --- a/configs/dcn/yolov3_r50vd_dcn_db_obj365_pretrained_coco.yml +++ b/configs/dcn/yolov3_r50vd_dcn_db_obj365_pretrained_coco.yml @@ -43,11 +43,6 @@ YOLOv3Head: keep_prob: 0.94 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 label_smooth: false use_fine_grained_loss: true diff --git a/configs/dcn/yolov3_r50vd_dcn_obj365_pretrained_coco.yml b/configs/dcn/yolov3_r50vd_dcn_obj365_pretrained_coco.yml index 014a7947e2d711af8d9be1d04139b5058b3b52bf..31e781980d9e63203c1f8e14ef4dddff0f59f7d9 100755 --- a/configs/dcn/yolov3_r50vd_dcn_obj365_pretrained_coco.yml +++ b/configs/dcn/yolov3_r50vd_dcn_obj365_pretrained_coco.yml @@ -41,11 +41,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: false use_fine_grained_loss: true diff --git a/configs/ppyolo/ppyolo.yml b/configs/ppyolo/ppyolo.yml index 59d5faa3a45a02cca84d15b48d25cac3d426a425..a1a9e99598512dd1683893d3c6b71a8a5ec7e581 100644 --- a/configs/ppyolo/ppyolo.yml +++ b/configs/ppyolo/ppyolo.yml @@ -44,7 +44,6 @@ YOLOv3Head: drop_block: true YOLOv3Loss: - batch_size: 24 ignore_thresh: 0.7 scale_x_y: 1.05 label_smooth: false diff --git a/configs/ppyolo/ppyolo_2x.yml b/configs/ppyolo/ppyolo_2x.yml index 8c2493372e7f5814dbaabd29d3ea78bc37647211..a781588679c1d45e4119a82df2518aa9e1f25896 100644 --- a/configs/ppyolo/ppyolo_2x.yml +++ b/configs/ppyolo/ppyolo_2x.yml @@ -44,7 +44,6 @@ YOLOv3Head: drop_block: true YOLOv3Loss: - batch_size: 24 ignore_thresh: 0.7 scale_x_y: 1.05 label_smooth: false diff --git a/configs/ppyolo/ppyolo_r18vd.yml b/configs/ppyolo/ppyolo_r18vd.yml index c054d5f5d574dc7419b07cbc8e4a22113f0778ae..a686a209960b87168c000bc141d6bdc545af6266 100755 --- a/configs/ppyolo/ppyolo_r18vd.yml +++ b/configs/ppyolo/ppyolo_r18vd.yml @@ -39,7 +39,6 @@ YOLOv3Head: drop_block: true YOLOv3Loss: - batch_size: 32 ignore_thresh: 0.7 scale_x_y: 1.05 label_smooth: false diff --git a/configs/ppyolo/ppyolo_test.yml b/configs/ppyolo/ppyolo_test.yml index 840865a0b8aac1a84724b3b03b24e32435992b02..a9b16dd44fce8f3269c088a995cd263bd6370480 100644 --- a/configs/ppyolo/ppyolo_test.yml +++ b/configs/ppyolo/ppyolo_test.yml @@ -47,7 +47,6 @@ YOLOv3Head: drop_block: true YOLOv3Loss: - batch_size: 24 ignore_thresh: 0.7 scale_x_y: 1.05 label_smooth: false diff --git a/configs/yolov3_darknet.yml b/configs/yolov3_darknet.yml index b84d811036da52d833f7c3cd1702d0b9148ac1a8..c3b4477f9c88d3a1fca5382f9fffa56826480845 100644 --- a/configs/yolov3_darknet.yml +++ b/configs/yolov3_darknet.yml @@ -35,11 +35,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: true diff --git a/configs/yolov3_darknet_voc.yml b/configs/yolov3_darknet_voc.yml index b1c48f5f6dfc64ce5c3d63ea4543b652905782cf..362989c2866facc54cec2987cb2a2bdd64a94c3e 100644 --- a/configs/yolov3_darknet_voc.yml +++ b/configs/yolov3_darknet_voc.yml @@ -36,11 +36,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: false diff --git a/configs/yolov3_darknet_voc_diouloss.yml b/configs/yolov3_darknet_voc_diouloss.yml index 62c912dc1dcdf3731271c1cfec8c6d90520bc86b..8a006fe8bd3206ea29eabe19a5654991e31d4a15 100644 --- a/configs/yolov3_darknet_voc_diouloss.yml +++ b/configs/yolov3_darknet_voc_diouloss.yml @@ -36,7 +36,6 @@ YOLOv3Head: score_threshold: 0.01 YOLOv3Loss: - batch_size: 8 ignore_thresh: 0.7 label_smooth: false iou_loss: DiouLossYolo diff --git a/configs/yolov3_mobilenet_v1.yml b/configs/yolov3_mobilenet_v1.yml index 040f0f2c935ebccfddad7513f2959b5ec31f5cea..3325bd4fbd1cbf0a938d6e28800e029308be3a79 100644 --- a/configs/yolov3_mobilenet_v1.yml +++ b/configs/yolov3_mobilenet_v1.yml @@ -36,11 +36,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: true diff --git a/configs/yolov3_mobilenet_v1_fruit.yml b/configs/yolov3_mobilenet_v1_fruit.yml index 78f50206e367862a6d9d8ccc65211bd328996ca4..b9e576c29b11a6ddb235ff3332d01c8df8148ba8 100644 --- a/configs/yolov3_mobilenet_v1_fruit.yml +++ b/configs/yolov3_mobilenet_v1_fruit.yml @@ -38,11 +38,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: true diff --git a/configs/yolov3_mobilenet_v1_voc.yml b/configs/yolov3_mobilenet_v1_voc.yml index 1b7097ad301ea17080e9fda5b166c9e7da0722e4..3df184b25c82f5743da27e2dd7f4fb846aca18b4 100644 --- a/configs/yolov3_mobilenet_v1_voc.yml +++ b/configs/yolov3_mobilenet_v1_voc.yml @@ -37,11 +37,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: false diff --git a/configs/yolov3_mobilenet_v3.yml b/configs/yolov3_mobilenet_v3.yml index 223d14c4909998b6d76f54ff3b45d6d1badd9d1e..d8526f6a82b07fcfbc916b1f0c753da96647aeec 100644 --- a/configs/yolov3_mobilenet_v3.yml +++ b/configs/yolov3_mobilenet_v3.yml @@ -38,11 +38,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: false diff --git a/configs/yolov3_r34.yml b/configs/yolov3_r34.yml index da887cf3d4d9921eb7102dec879c05571111d3e1..ca4d50b4ccfd48b302dd5c9dcb9badde10d1ed46 100644 --- a/configs/yolov3_r34.yml +++ b/configs/yolov3_r34.yml @@ -38,11 +38,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: true diff --git a/configs/yolov3_r34_voc.yml b/configs/yolov3_r34_voc.yml index 2d980dd0c2129b16bc5d50b45a103f68203d0a7c..6aa4aa74c88150b9fe6773eb95db28181a6fb6fa 100644 --- a/configs/yolov3_r34_voc.yml +++ b/configs/yolov3_r34_voc.yml @@ -39,11 +39,6 @@ YOLOv3Head: score_threshold: 0.01 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 label_smooth: false diff --git a/configs/yolov4/yolov4_cspdarknet.yml b/configs/yolov4/yolov4_cspdarknet.yml index 4411b054fff7e420fd6eed6bec0d4673f3140c1b..cbc69d12252f0e540f49aa16efb4fed2051da694 100644 --- a/configs/yolov4/yolov4_cspdarknet.yml +++ b/configs/yolov4/yolov4_cspdarknet.yml @@ -35,11 +35,6 @@ YOLOv4Head: scale_x_y: [1.2, 1.1, 1.05] 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 label_smooth: true downsample: [8,16,32] diff --git a/configs/yolov4/yolov4_cspdarknet_coco.yml b/configs/yolov4/yolov4_cspdarknet_coco.yml index 8b4a15dc530d491c2bf985e27948d5571a5d6489..a711a177aa02908d1a77b229937c0913a9341cc5 100644 --- a/configs/yolov4/yolov4_cspdarknet_coco.yml +++ b/configs/yolov4/yolov4_cspdarknet_coco.yml @@ -34,11 +34,6 @@ YOLOv4Head: scale_x_y: [1.2, 1.1, 1.05] 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 label_smooth: true downsample: [8,16,32] diff --git a/configs/yolov4/yolov4_cspdarknet_voc.yml b/configs/yolov4/yolov4_cspdarknet_voc.yml index beefaa0f153ca8f9fd0541907628a2c02854024c..3f2af08a6868629ab3f513bcc087e264abb14d1d 100644 --- a/configs/yolov4/yolov4_cspdarknet_voc.yml +++ b/configs/yolov4/yolov4_cspdarknet_voc.yml @@ -34,11 +34,6 @@ YOLOv4Head: scale_x_y: [1.2, 1.1, 1.05] 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 label_smooth: true downsample: [8,16,32] diff --git a/ppdet/core/workspace.py b/ppdet/core/workspace.py index b7f7370b4bbbe023b2ffe7a18d77255dc275d44b..a5124b5cd9526d9e77391a5af29a6da0cc1feb28 100644 --- a/ppdet/core/workspace.py +++ b/ppdet/core/workspace.py @@ -97,6 +97,15 @@ def load_config(file_path): del cfg[READER_KEY] 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 diff --git a/ppdet/modeling/losses/yolo_loss.py b/ppdet/modeling/losses/yolo_loss.py index 6823c024bc5aea54c4f9b5195da03cb16dfee8a3..e978eb992ec0aca9038e61ebb367cd47e6885a7b 100644 --- a/ppdet/modeling/losses/yolo_loss.py +++ b/ppdet/modeling/losses/yolo_loss.py @@ -32,17 +32,17 @@ class YOLOv3Loss(object): Combined loss for YOLOv3 network Args: - batch_size (int): training batch size + train_batch_size (int): training batch size ignore_thresh (float): threshold to ignore confidence loss label_smooth (bool): whether to use label smoothing use_fine_grained_loss (bool): whether use fine grained YOLOv3 loss instead of fluid.layers.yolov3_loss """ __inject__ = ['iou_loss', 'iou_aware_loss'] - __shared__ = ['use_fine_grained_loss'] + __shared__ = ['use_fine_grained_loss', 'train_batch_size'] def __init__(self, - batch_size=8, + train_batch_size=8, ignore_thresh=0.7, label_smooth=True, use_fine_grained_loss=False, @@ -51,7 +51,7 @@ class YOLOv3Loss(object): downsample=[32, 16, 8], scale_x_y=1., match_score=False): - self._batch_size = batch_size + self._train_batch_size = train_batch_size self._ignore_thresh = ignore_thresh self._label_smooth = label_smooth self._use_fine_grained_loss = use_fine_grained_loss @@ -65,7 +65,7 @@ class YOLOv3Loss(object): anchor_masks, mask_anchors, num_classes, prefix_name): if self._use_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) else: losses = [] @@ -95,7 +95,7 @@ class YOLOv3Loss(object): outputs, targets, gt_box, - batch_size, + train_batch_size, num_classes, mask_anchors, ignore_thresh, @@ -108,7 +108,7 @@ class YOLOv3Loss(object): targets ([Variables]): List of Variables, The targets for yolo loss calculatation. 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 mask_anchors ([[float]]): list of anchors in each output layer ignore_thresh (float): prediction bbox overlap any gt_box greater @@ -171,7 +171,7 @@ class YOLOv3Loss(object): loss_h = fluid.layers.reduce_sum(loss_h, dim=[1, 2, 3]) if self._iou_loss is not None: 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) loss_iou = loss_iou * tscale_tobj loss_iou = fluid.layers.reduce_sum(loss_iou, dim=[1, 2, 3]) @@ -180,14 +180,14 @@ class YOLOv3Loss(object): if self._iou_aware_loss is not None: loss_iou_aware = self._iou_aware_loss( 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 = fluid.layers.reduce_sum( loss_iou_aware, dim=[1, 2, 3]) loss_iou_awares.append(fluid.layers.reduce_mean(loss_iou_aware)) 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) loss_cls = fluid.layers.sigmoid_cross_entropy_with_logits(cls, tcls)