Fix bug #541 #542 (#545)
Browse files* fix #541 #542
* Update train.py
Co-authored-by: Glenn Jocher <[email protected]>
- train.py +1 -1
- utils/utils.py +2 -2
train.py
CHANGED
@@ -377,7 +377,7 @@ def train(hyp, tb_writer, opt, device):
|
|
377 |
|
378 |
# Save last, best and delete
|
379 |
torch.save(ckpt, last)
|
380 |
-
if
|
381 |
torch.save(ckpt, best)
|
382 |
del ckpt
|
383 |
# end epoch ----------------------------------------------------------------------------------------------------
|
|
|
377 |
|
378 |
# Save last, best and delete
|
379 |
torch.save(ckpt, last)
|
380 |
+
if best_fitness == fi:
|
381 |
torch.save(ckpt, best)
|
382 |
del ckpt
|
383 |
# end epoch ----------------------------------------------------------------------------------------------------
|
utils/utils.py
CHANGED
@@ -346,8 +346,8 @@ def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False):
|
|
346 |
elif CIoU: # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47
|
347 |
v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / h2) - torch.atan(w1 / h1), 2)
|
348 |
with torch.no_grad():
|
349 |
-
alpha = v / (1 - iou + v)
|
350 |
-
return iou - (rho2 / c2 + v * alpha) # CIoU
|
351 |
|
352 |
return iou
|
353 |
|
|
|
346 |
elif CIoU: # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47
|
347 |
v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / h2) - torch.atan(w1 / h1), 2)
|
348 |
with torch.no_grad():
|
349 |
+
alpha = v / (1 - iou + v + 1e-16)
|
350 |
+
return iou - (rho2 / c2 + v * alpha ) # CIoU
|
351 |
|
352 |
return iou
|
353 |
|