This commit is contained in:
Glenn Jocher 2019-07-15 16:27:13 +02:00
parent e73e247442
commit 4e5a00fb72
3 changed files with 13 additions and 5 deletions

View File

@ -4,7 +4,7 @@
# subdivisions=1 # subdivisions=1
# Training # Training
batch=64 batch=64
subdivisions=64 subdivisions=32
width=608 width=608
height=608 height=608
channels=3 channels=3

View File

@ -88,6 +88,9 @@ def test(
stats.append(([], torch.Tensor(), torch.Tensor(), tcls)) stats.append(([], torch.Tensor(), torch.Tensor(), tcls))
continue continue
# Clip boxes to image bounds
clip_coords(pred, shapes[si])
# Append to text file # Append to text file
# with open('test.txt', 'a') as file: # with open('test.txt', 'a') as file:
# [file.write('%11.5g' * 7 % tuple(x) + '\n') for x in pred] # [file.write('%11.5g' * 7 % tuple(x) + '\n') for x in pred]

View File

@ -125,16 +125,21 @@ def xywh2xyxy(x):
def scale_coords(img1_shape, coords, img0_shape): def scale_coords(img1_shape, coords, img0_shape):
# Rescale coords1 (xyxy) from img1_shape to img0_shape # Rescale coords (xyxy) from img1_shape to img0_shape
gain = max(img1_shape) / max(img0_shape) # gain = old / new gain = max(img1_shape) / max(img0_shape) # gain = old / new
coords[:, [0, 2]] -= (img1_shape[1] - img0_shape[1] * gain) / 2 # x padding coords[:, [0, 2]] -= (img1_shape[1] - img0_shape[1] * gain) / 2 # x padding
coords[:, [1, 3]] -= (img1_shape[0] - img0_shape[0] * gain) / 2 # y padding coords[:, [1, 3]] -= (img1_shape[0] - img0_shape[0] * gain) / 2 # y padding
coords[:, :4] /= gain coords[:, :4] /= gain
coords[:, [0, 2]] = coords[:, [0, 2]].clamp(min=0, max=img0_shape[1]) # clip x clip_coords(coords, img0_shape)
coords[:, [1, 3]] = coords[:, [1, 3]].clamp(min=0, max=img0_shape[0]) # clip y
return coords return coords
def clip_coords(boxes, img_shape):
# Clip bounding xyxy bounding boxes to image shape (height, width)
boxes[:, [0, 2]] = boxes[:, [0, 2]].clamp(min=0, max=img_shape[1]) # clip x
boxes[:, [1, 3]] = boxes[:, [1, 3]].clamp(min=0, max=img_shape[0]) # clip y
def ap_per_class(tp, conf, pred_cls, target_cls): def ap_per_class(tp, conf, pred_cls, target_cls):
""" Compute the average precision, given the recall and precision curves. """ Compute the average precision, given the recall and precision curves.
Source: https://github.com/rafaelpadilla/Object-Detection-Metrics. Source: https://github.com/rafaelpadilla/Object-Detection-Metrics.