glenn-jocher
commited on
Commit
•
404749a
1
Parent(s):
a5d5f92
PyTorch Hub results.save('path/to/dir') (#2179)
Browse files- models/common.py +5 -4
models/common.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
# This file contains modules common to various models
|
2 |
|
3 |
import math
|
|
|
4 |
|
5 |
import numpy as np
|
6 |
import requests
|
@@ -241,7 +242,7 @@ class Detections:
|
|
241 |
self.xywhn = [x / g for x, g in zip(self.xywh, gn)] # xywh normalized
|
242 |
self.n = len(self.pred)
|
243 |
|
244 |
-
def display(self, pprint=False, show=False, save=False, render=False):
|
245 |
colors = color_list()
|
246 |
for i, (img, pred) in enumerate(zip(self.imgs, self.pred)):
|
247 |
str = f'image {i + 1}/{len(self.pred)}: {img.shape[0]}x{img.shape[1]} '
|
@@ -259,7 +260,7 @@ class Detections:
|
|
259 |
if show:
|
260 |
img.show(f'image {i}') # show
|
261 |
if save:
|
262 |
-
f = f'results{i}.jpg'
|
263 |
img.save(f) # save
|
264 |
print(f"{'Saving' * (i == 0)} {f},", end='' if i < self.n - 1 else ' done.\n')
|
265 |
if render:
|
@@ -271,8 +272,8 @@ class Detections:
|
|
271 |
def show(self):
|
272 |
self.display(show=True) # show results
|
273 |
|
274 |
-
def save(self):
|
275 |
-
self.display(save=True) # save results
|
276 |
|
277 |
def render(self):
|
278 |
self.display(render=True) # render results
|
|
|
1 |
# This file contains modules common to various models
|
2 |
|
3 |
import math
|
4 |
+
from pathlib import Path
|
5 |
|
6 |
import numpy as np
|
7 |
import requests
|
|
|
242 |
self.xywhn = [x / g for x, g in zip(self.xywh, gn)] # xywh normalized
|
243 |
self.n = len(self.pred)
|
244 |
|
245 |
+
def display(self, pprint=False, show=False, save=False, render=False, save_dir=''):
|
246 |
colors = color_list()
|
247 |
for i, (img, pred) in enumerate(zip(self.imgs, self.pred)):
|
248 |
str = f'image {i + 1}/{len(self.pred)}: {img.shape[0]}x{img.shape[1]} '
|
|
|
260 |
if show:
|
261 |
img.show(f'image {i}') # show
|
262 |
if save:
|
263 |
+
f = Path(save_dir) / f'results{i}.jpg'
|
264 |
img.save(f) # save
|
265 |
print(f"{'Saving' * (i == 0)} {f},", end='' if i < self.n - 1 else ' done.\n')
|
266 |
if render:
|
|
|
272 |
def show(self):
|
273 |
self.display(show=True) # show results
|
274 |
|
275 |
+
def save(self, save_dir=''):
|
276 |
+
self.display(save=True, save_dir=save_dir) # save results
|
277 |
|
278 |
def render(self):
|
279 |
self.display(render=True) # render results
|