From a0a4adf6de4de3d9d5ac00c23796c844a8e57200 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 24 Mar 2022 11:31:22 +0100 Subject: [PATCH] Add PyTorch Hub `results.save(labels=False)` option (#7129) Resolves https://github.com/ultralytics/yolov5/issues/388#issuecomment-1077121821 --- models/common.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/models/common.py b/models/common.py index 0286c74fe8cd..115e3c3145ff 100644 --- a/models/common.py +++ b/models/common.py @@ -131,7 +131,7 @@ def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5): # ch_in, ch_out, nu c_ = int(c2 * e) # hidden channels self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c1, c_, 1, 1) - self.cv3 = Conv(2 * c_, c2, 1) # act=FReLU(c2) + self.cv3 = Conv(2 * c_, c2, 1) # optional act=FReLU(c2) self.m = nn.Sequential(*(Bottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n))) # self.m = nn.Sequential(*(CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n))) @@ -589,7 +589,7 @@ def __init__(self, imgs, pred, files, times=(0, 0, 0, 0), names=None, shape=None self.t = tuple((times[i + 1] - times[i]) * 1000 / self.n for i in range(3)) # timestamps (ms) self.s = shape # inference BCHW shape - def display(self, pprint=False, show=False, save=False, crop=False, render=False, save_dir=Path('')): + def display(self, pprint=False, show=False, save=False, crop=False, render=False, labels=True, save_dir=Path('')): crops = [] for i, (im, pred) in enumerate(zip(self.imgs, self.pred)): s = f'image {i + 1}/{len(self.pred)}: {im.shape[0]}x{im.shape[1]} ' # string @@ -606,7 +606,7 @@ def display(self, pprint=False, show=False, save=False, crop=False, render=False crops.append({'box': box, 'conf': conf, 'cls': cls, 'label': label, 'im': save_one_box(box, im, file=file, save=save)}) else: # all others - annotator.box_label(box, label, color=colors(cls)) + annotator.box_label(box, label if labels else '', color=colors(cls)) im = annotator.im else: s += '(no detections)' @@ -633,19 +633,19 @@ def print(self): LOGGER.info(f'Speed: %.1fms pre-process, %.1fms inference, %.1fms NMS per image at shape {tuple(self.s)}' % self.t) - def show(self): - self.display(show=True) # show results + def show(self, labels=True): + self.display(show=True, labels=labels) # show results - def save(self, save_dir='runs/detect/exp'): + def save(self, labels=True, save_dir='runs/detect/exp'): save_dir = increment_path(save_dir, exist_ok=save_dir != 'runs/detect/exp', mkdir=True) # increment save_dir - self.display(save=True, save_dir=save_dir) # save results + self.display(save=True, labels=labels, save_dir=save_dir) # save results def crop(self, save=True, save_dir='runs/detect/exp'): save_dir = increment_path(save_dir, exist_ok=save_dir != 'runs/detect/exp', mkdir=True) if save else None return self.display(crop=True, save=save, save_dir=save_dir) # crop results - def render(self): - self.display(render=True) # render results + def render(self, labels=True): + self.display(render=True, labels=labels) # render results return self.imgs def pandas(self):