updates
This commit is contained in:
+16
-2
@@ -71,7 +71,8 @@ def weights_init_normal(m):
|
||||
torch.nn.init.constant_(m.bias.data, 0.0)
|
||||
|
||||
|
||||
def xyxy2xywh(x): # Convert bounding box format from [x1, y1, x2, y2] to [x, y, w, h]
|
||||
def xyxy2xywh(x):
|
||||
# Convert bounding box format from [x1, y1, x2, y2] to [x, y, w, h]
|
||||
y = torch.zeros(x.shape) if x.dtype is torch.float32 else np.zeros(x.shape)
|
||||
y[:, 0] = (x[:, 0] + x[:, 2]) / 2
|
||||
y[:, 1] = (x[:, 1] + x[:, 3]) / 2
|
||||
@@ -80,7 +81,8 @@ def xyxy2xywh(x): # Convert bounding box format from [x1, y1, x2, y2] to [x, y,
|
||||
return y
|
||||
|
||||
|
||||
def xywh2xyxy(x): # Convert bounding box format from [x, y, w, h] to [x1, y1, x2, y2]
|
||||
def xywh2xyxy(x):
|
||||
# Convert bounding box format from [x, y, w, h] to [x1, y1, x2, y2]
|
||||
y = torch.zeros(x.shape) if x.dtype is torch.float32 else np.zeros(x.shape)
|
||||
y[:, 0] = (x[:, 0] - x[:, 2] / 2)
|
||||
y[:, 1] = (x[:, 1] - x[:, 3] / 2)
|
||||
@@ -89,6 +91,18 @@ def xywh2xyxy(x): # Convert bounding box format from [x, y, w, h] to [x1, y1, x
|
||||
return y
|
||||
|
||||
|
||||
def scale_coords(img_size, coords, img0_shape):
|
||||
# Rescale x1, y1, x2, y2 from 416 to image size
|
||||
gain = float(img_size) / max(img0_shape) # gain = old / new
|
||||
pad_x = (img_size - img0_shape[1] * gain) / 2 # width padding
|
||||
pad_y = (img_size - img0_shape[0] * gain) / 2 # height padding
|
||||
coords[:, [0, 2]] -= pad_x
|
||||
coords[:, [1, 3]] -= pad_y
|
||||
coords[:, :4] /= gain
|
||||
coords[:, :4] = torch.round(torch.clamp(coords[:, :4], min=0))
|
||||
return coords
|
||||
|
||||
|
||||
def ap_per_class(tp, conf, pred_cls, target_cls):
|
||||
""" Compute the average precision, given the recall and precision curves.
|
||||
Method originally from https://github.com/rafaelpadilla/Object-Detection-Metrics.
|
||||
|
||||
Reference in New Issue
Block a user