From 479122b0adaa7d9cc89c076b17de228223892a7b Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 1 Apr 2021 18:58:53 +0200 Subject: [PATCH 1/2] PyTorch Hub model.save() increment as runs/hub/exp This chane will align PyTorch Hub results saving with the existing unified results saving directory structure of runs/ /train /detect /test /hub /exp /exp2 ... --- models/common.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/models/common.py b/models/common.py index a25172dcfcac..eefae7990983 100644 --- a/models/common.py +++ b/models/common.py @@ -11,7 +11,7 @@ from torch.cuda import amp from utils.datasets import letterbox -from utils.general import non_max_suppression, make_divisible, scale_coords, xyxy2xywh +from utils.general import non_max_suppression, make_divisible, scale_coords, increment_path, xyxy2xywh from utils.plots import color_list, plot_one_box from utils.torch_utils import time_synchronized @@ -324,9 +324,9 @@ def display(self, pprint=False, show=False, save=False, render=False, save_dir=' if show: img.show(self.files[i]) # show if save: - f = Path(save_dir) / self.files[i] - img.save(f) # save - print(f"{'Saving' * (i == 0)} {f},", end='' if i < self.n - 1 else ' done.\n') + f = self.files[i] + img.save(Path(save_dir) / f) # save + print(f"{'Saved' * (i == 0)} {f},", end='' if i < self.n - 1 else f' to {save_dir}\n') if render: self.imgs[i] = np.asarray(img) @@ -337,8 +337,9 @@ def print(self): def show(self): self.display(show=True) # show results - def save(self, save_dir='results/'): - Path(save_dir).mkdir(exist_ok=True) + def save(self, save_dir='runs/hub/exp'): + save_dir = increment_path(save_dir, exist_ok=save_dir != 'runs/hub/exp') # increment save_dir + Path(save_dir).mkdir(parents=True, exist_ok=True) self.display(save=True, save_dir=save_dir) # save results def render(self): From 57684a01ec8ebb3c844adfbe5fe49773140c8e03 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 1 Apr 2021 19:03:35 +0200 Subject: [PATCH 2/2] cleanup --- models/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/common.py b/models/common.py index eefae7990983..9970fbc8e2d9 100644 --- a/models/common.py +++ b/models/common.py @@ -326,7 +326,7 @@ def display(self, pprint=False, show=False, save=False, render=False, save_dir=' if save: f = self.files[i] img.save(Path(save_dir) / f) # save - print(f"{'Saved' * (i == 0)} {f},", end='' if i < self.n - 1 else f' to {save_dir}\n') + print(f"{'Saved' * (i == 0)} {f}", end=',' if i < self.n - 1 else f' to {save_dir}\n') if render: self.imgs[i] = np.asarray(img)