From 8f354362cd94c70908bf6168951b07bd32715ebe Mon Sep 17 00:00:00 2001 From: Yono Mittlefehldt Date: Sat, 11 Dec 2021 18:40:37 +0100 Subject: [PATCH 1/2] Fix Detections class `tolist()` method (#5945) * Fix tolist() to add the file for each Detection * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix PEP8 requirement for 2 spaces before an inline comment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Cleanup Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher --- models/common.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/models/common.py b/models/common.py index b39017378..c2edff4d3 100644 --- a/models/common.py +++ b/models/common.py @@ -525,7 +525,7 @@ class AutoShape(nn.Module): class Detections: # YOLOv5 detections class for inference results - def __init__(self, imgs, pred, files, times=None, names=None, shape=None): + def __init__(self, imgs, pred, files, times=(0, 0, 0, 0), names=None, shape=None): super().__init__() d = pred[0].device # device gn = [torch.tensor([*(im.shape[i] for i in [1, 0, 1, 0]), 1, 1], device=d) for im in imgs] # normalizations @@ -533,6 +533,7 @@ class Detections: self.pred = pred # list of tensors pred[0] = (xyxy, conf, cls) self.names = names # class names self.files = files # image filenames + self.times = times # profiling times self.xyxy = pred # xyxy pixels self.xywh = [xyxy2xywh(x) for x in pred] # xywh pixels self.xyxyn = [x / g for x, g in zip(self.xyxy, gn)] # xyxy normalized @@ -612,10 +613,11 @@ class Detections: def tolist(self): # return a list of Detections objects, i.e. 'for result in results.tolist():' - x = [Detections([self.imgs[i]], [self.pred[i]], names=self.names, shape=self.s) for i in range(self.n)] - for d in x: - for k in ['imgs', 'pred', 'xyxy', 'xyxyn', 'xywh', 'xywhn']: - setattr(d, k, getattr(d, k)[0]) # pop out of list + r = range(self.n) # iterable + x = [Detections([self.imgs[i]], [self.pred[i]], [self.files[i]], self.times, self.names, self.s) for i in r] + # for d in x: + # for k in ['imgs', 'pred', 'xyxy', 'xyxyn', 'xywh', 'xywhn']: + # setattr(d, k, getattr(d, k)[0]) # pop out of list return x def __len__(self): From 19c56e60b100cf8ff9af65b4347de69e0cff76ae Mon Sep 17 00:00:00 2001 From: Diego Montes <54745152+d57montes@users.noreply.github.com> Date: Sun, 12 Dec 2021 17:39:14 -0500 Subject: [PATCH 2/2] Fix `imgsz` bug (#5948) * fix imgsz bug * Update detect.py Co-authored-by: Glenn Jocher --- detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detect.py b/detect.py index 0b6875e55..14cdf96ca 100644 --- a/detect.py +++ b/detect.py @@ -38,7 +38,7 @@ from utils.torch_utils import select_device, time_sync @torch.no_grad() def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s) source=ROOT / 'data/images', # file/dir/URL/glob, 0 for webcam - imgsz=640, # inference size (pixels) + imgsz=(640, 640), # inference size (height, width) conf_thres=0.25, # confidence threshold iou_thres=0.45, # NMS IOU threshold max_det=1000, # maximum detections per image