From 4e5a00fb72335ab393b7a45903f7312ba33e773a Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 15 Jul 2019 16:27:13 +0200 Subject: [PATCH] updates --- cfg/yolov3-spp-1cls.cfg | 2 +- test.py | 3 +++ utils/utils.py | 13 +++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cfg/yolov3-spp-1cls.cfg b/cfg/yolov3-spp-1cls.cfg index 3e633973..9e989e91 100644 --- a/cfg/yolov3-spp-1cls.cfg +++ b/cfg/yolov3-spp-1cls.cfg @@ -4,7 +4,7 @@ # subdivisions=1 # Training batch=64 -subdivisions=64 +subdivisions=32 width=608 height=608 channels=3 diff --git a/test.py b/test.py index e1563d26..051f5fc7 100644 --- a/test.py +++ b/test.py @@ -88,6 +88,9 @@ def test( stats.append(([], torch.Tensor(), torch.Tensor(), tcls)) continue + # Clip boxes to image bounds + clip_coords(pred, shapes[si]) + # Append to text file # with open('test.txt', 'a') as file: # [file.write('%11.5g' * 7 % tuple(x) + '\n') for x in pred] diff --git a/utils/utils.py b/utils/utils.py index 7fda5289..6f492fcf 100755 --- a/utils/utils.py +++ b/utils/utils.py @@ -125,16 +125,21 @@ def xywh2xyxy(x): 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 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[:, :4] /= gain - coords[:, [0, 2]] = coords[:, [0, 2]].clamp(min=0, max=img0_shape[1]) # clip x - coords[:, [1, 3]] = coords[:, [1, 3]].clamp(min=0, max=img0_shape[0]) # clip y + clip_coords(coords, img0_shape) 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): """ Compute the average precision, given the recall and precision curves. Source: https://github.com/rafaelpadilla/Object-Detection-Metrics. @@ -582,7 +587,7 @@ def kmeans_targets(path='./data/coco_64img.txt'): # from utils.utils import *; # Plotting functions --------------------------------------------------------------------------------------------------- def plot_one_box(x, img, color=None, label=None, line_thickness=None): # Plots one bounding box on image img - tl = line_thickness or round(0.002 * (img.shape[0]+img.shape[1])/2) + 1 # line thickness + tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line thickness color = color or [random.randint(0, 255) for _ in range(3)] c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3])) cv2.rectangle(img, c1, c2, color, thickness=tl)