non-max-suppression function fixed for one class model conf. (#305)

This commit is contained in:
Mohammad Khoshbin 2022-07-27 19:17:28 +04:30 committed by GitHub
parent 7a7cba744a
commit a4724d5592
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -645,7 +645,11 @@ def non_max_suppression(prediction, conf_thres=0.25, iou_thres=0.45, classes=Non
continue
# Compute conf
x[:, 5:] *= x[:, 4:5] # conf = obj_conf * cls_conf
if nc == 1:
x[:, 5:] = x[:, 4:5] # for models with one class, cls_loss is 0 and cls_conf is always 0.5,
# so there is no need to multiplicate.
else:
x[:, 5:] *= x[:, 4:5] # conf = obj_conf * cls_conf
# Box (center x, center y, width, height) to (x1, y1, x2, y2)
box = xywh2xyxy(x[:, :4])