Commit
•
9c803f2
1
Parent(s):
fd16799
Add --label-smoothing eps argument to train.py (default 0.0) (#2344)
Browse files* Add label smoothing option
* Correct data type
* add_log
* Remove log
* Add log
* Update loss.py
remove comment (too versbose)
Co-authored-by: phattran <phat.tranhoang@cyberlogitec.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
- train.py +2 -0
- utils/loss.py +1 -1
train.py
CHANGED
@@ -224,6 +224,7 @@ def train(hyp, opt, device, tb_writer=None):
|
|
224 |
hyp['box'] *= 3. / nl # scale to layers
|
225 |
hyp['cls'] *= nc / 80. * 3. / nl # scale to classes and layers
|
226 |
hyp['obj'] *= (imgsz / 640) ** 2 * 3. / nl # scale to image size and layers
|
|
|
227 |
model.nc = nc # attach number of classes to model
|
228 |
model.hyp = hyp # attach hyperparameters to model
|
229 |
model.gr = 1.0 # iou loss ratio (obj_loss = 1.0 or iou)
|
@@ -481,6 +482,7 @@ if __name__ == '__main__':
|
|
481 |
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
|
482 |
parser.add_argument('--quad', action='store_true', help='quad dataloader')
|
483 |
parser.add_argument('--linear-lr', action='store_true', help='linear LR')
|
|
|
484 |
parser.add_argument('--upload_dataset', action='store_true', help='Upload dataset as W&B artifact table')
|
485 |
parser.add_argument('--bbox_interval', type=int, default=-1, help='Set bounding-box image logging interval for W&B')
|
486 |
parser.add_argument('--save_period', type=int, default=-1, help='Log model after every "save_period" epoch')
|
|
|
224 |
hyp['box'] *= 3. / nl # scale to layers
|
225 |
hyp['cls'] *= nc / 80. * 3. / nl # scale to classes and layers
|
226 |
hyp['obj'] *= (imgsz / 640) ** 2 * 3. / nl # scale to image size and layers
|
227 |
+
hyp['label_smoothing'] = opt.label_smoothing
|
228 |
model.nc = nc # attach number of classes to model
|
229 |
model.hyp = hyp # attach hyperparameters to model
|
230 |
model.gr = 1.0 # iou loss ratio (obj_loss = 1.0 or iou)
|
|
|
482 |
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
|
483 |
parser.add_argument('--quad', action='store_true', help='quad dataloader')
|
484 |
parser.add_argument('--linear-lr', action='store_true', help='linear LR')
|
485 |
+
parser.add_argument('--label-smoothing', type=float, default=0.0, help='Label smoothing epsilon')
|
486 |
parser.add_argument('--upload_dataset', action='store_true', help='Upload dataset as W&B artifact table')
|
487 |
parser.add_argument('--bbox_interval', type=int, default=-1, help='Set bounding-box image logging interval for W&B')
|
488 |
parser.add_argument('--save_period', type=int, default=-1, help='Log model after every "save_period" epoch')
|
utils/loss.py
CHANGED
@@ -97,7 +97,7 @@ class ComputeLoss:
|
|
97 |
BCEobj = nn.BCEWithLogitsLoss(pos_weight=torch.tensor([h['obj_pw']], device=device))
|
98 |
|
99 |
# Class label smoothing https://arxiv.org/pdf/1902.04103.pdf eqn 3
|
100 |
-
self.cp, self.cn = smooth_BCE(eps=0.0)
|
101 |
|
102 |
# Focal loss
|
103 |
g = h['fl_gamma'] # focal loss gamma
|
|
|
97 |
BCEobj = nn.BCEWithLogitsLoss(pos_weight=torch.tensor([h['obj_pw']], device=device))
|
98 |
|
99 |
# Class label smoothing https://arxiv.org/pdf/1902.04103.pdf eqn 3
|
100 |
+
self.cp, self.cn = smooth_BCE(eps=h.get('label_smoothing', 0.0)) # positive, negative BCE targets
|
101 |
|
102 |
# Focal loss
|
103 |
g = h['fl_gamma'] # focal loss gamma
|