PyTorch Hub model.save() increment as runs/hub/exp (#2684)
Browse files* 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
...
* cleanup
- models/common.py +7 -6
models/common.py
CHANGED
@@ -11,7 +11,7 @@ from PIL import Image
|
|
11 |
from torch.cuda import amp
|
12 |
|
13 |
from utils.datasets import letterbox
|
14 |
-
from utils.general import non_max_suppression, make_divisible, scale_coords, xyxy2xywh
|
15 |
from utils.plots import color_list, plot_one_box
|
16 |
from utils.torch_utils import time_synchronized
|
17 |
|
@@ -324,9 +324,9 @@ class Detections:
|
|
324 |
if show:
|
325 |
img.show(self.files[i]) # show
|
326 |
if save:
|
327 |
-
f =
|
328 |
-
img.save(f) # save
|
329 |
-
print(f"{'
|
330 |
if render:
|
331 |
self.imgs[i] = np.asarray(img)
|
332 |
|
@@ -337,8 +337,9 @@ class Detections:
|
|
337 |
def show(self):
|
338 |
self.display(show=True) # show results
|
339 |
|
340 |
-
def save(self, save_dir='
|
341 |
-
|
|
|
342 |
self.display(save=True, save_dir=save_dir) # save results
|
343 |
|
344 |
def render(self):
|
|
|
11 |
from torch.cuda import amp
|
12 |
|
13 |
from utils.datasets import letterbox
|
14 |
+
from utils.general import non_max_suppression, make_divisible, scale_coords, increment_path, xyxy2xywh
|
15 |
from utils.plots import color_list, plot_one_box
|
16 |
from utils.torch_utils import time_synchronized
|
17 |
|
|
|
324 |
if show:
|
325 |
img.show(self.files[i]) # show
|
326 |
if save:
|
327 |
+
f = self.files[i]
|
328 |
+
img.save(Path(save_dir) / f) # save
|
329 |
+
print(f"{'Saved' * (i == 0)} {f}", end=',' if i < self.n - 1 else f' to {save_dir}\n')
|
330 |
if render:
|
331 |
self.imgs[i] = np.asarray(img)
|
332 |
|
|
|
337 |
def show(self):
|
338 |
self.display(show=True) # show results
|
339 |
|
340 |
+
def save(self, save_dir='runs/hub/exp'):
|
341 |
+
save_dir = increment_path(save_dir, exist_ok=save_dir != 'runs/hub/exp') # increment save_dir
|
342 |
+
Path(save_dir).mkdir(parents=True, exist_ok=True)
|
343 |
self.display(save=True, save_dir=save_dir) # save results
|
344 |
|
345 |
def render(self):
|