From 926447e8c48e5a81bfbdef440a603c5787c43b9a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 17 Aug 2019 17:10:57 +0200 Subject: [PATCH] updates --- models.py | 11 ++++++++--- utils/utils.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/models.py b/models.py index eb2fdcea..936f5696 100755 --- a/models.py +++ b/models.py @@ -155,9 +155,14 @@ class YOLOLayer(nn.Module): # io[..., 2:4] = ((torch.sigmoid(io[..., 2:4]) * 2) ** 3) * self.anchor_wh # wh power method io[..., :4] *= self.stride - io[..., 4:] = torch.sigmoid(io[..., 4:]) # p_conf, p_cls - # io[..., 4:] = F.softmax(io[..., 4:], dim=4) # unified detection CE - # io[..., 4] = io[..., 5:].max(4)[0] # unified detection BCE + arc = 'normal' # (normal, uCE uBCE) architecture types + if arc == 'normal': + io[..., 4:] = torch.sigmoid(io[..., 4:]) + elif arc == 'uCE': + io[..., 4:] = F.softmax(io[..., 4:], dim=4) # unified detection CE + io[..., 4] = 1 + elif arc == 'uBCE': + io[..., 4] = io[..., 5:].max(4)[0] # unified detection BCE if self.nc == 1: io[..., 5] = 1 # single-class model https://github.com/ultralytics/yolov3/issues/235 diff --git a/utils/utils.py b/utils/utils.py index 10e39fc6..dec6bf55 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -63,7 +63,7 @@ def labels_to_class_weights(labels, nc=80): # Prepend gridpoint count (for uCE trianing) # gpi = ((320 / 32 * np.array([1, 2, 4])) ** 2 * 3).sum() # gridpoints per image - # weights = np.hstack([gpi * ni, weights]) # prepend gridpoints to start + # weights = np.hstack([gpi * ni - weights.sum() * 9, weights * 9]) ** 0.5 # prepend gridpoints to start weights[weights == 0] = 1 # replace empty bins with 1 weights = 1 / weights # number of targets per class