Improve plots.py robustness (#5616)
Browse files* Improve plots.py robustness
Addresses issues #5374, #5395, #5611
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- utils/plots.py +8 -2
utils/plots.py
CHANGED
@@ -17,7 +17,8 @@ import seaborn as sn
|
|
17 |
import torch
|
18 |
from PIL import Image, ImageDraw, ImageFont
|
19 |
|
20 |
-
from utils.general import clip_coords, increment_path, is_ascii, is_chinese,
|
|
|
21 |
from utils.metrics import fitness
|
22 |
|
23 |
# Settings
|
@@ -58,7 +59,10 @@ def check_font(font='Arial.ttf', size=10):
|
|
58 |
url = "https://ultralytics.com/assets/" + font.name
|
59 |
print(f'Downloading {url} to {font}...')
|
60 |
torch.hub.download_url_to_file(url, str(font), progress=False)
|
61 |
-
|
|
|
|
|
|
|
62 |
|
63 |
|
64 |
class Annotator:
|
@@ -320,6 +324,8 @@ def plot_val_study(file='', dir='', x=None): # from utils.plots import *; plot_
|
|
320 |
plt.savefig(f, dpi=300)
|
321 |
|
322 |
|
|
|
|
|
323 |
def plot_labels(labels, names=(), save_dir=Path('')):
|
324 |
# plot dataset labels
|
325 |
print('Plotting labels... ')
|
|
|
17 |
import torch
|
18 |
from PIL import Image, ImageDraw, ImageFont
|
19 |
|
20 |
+
from utils.general import (Timeout, check_requirements, clip_coords, increment_path, is_ascii, is_chinese, try_except,
|
21 |
+
user_config_dir, xywh2xyxy, xyxy2xywh)
|
22 |
from utils.metrics import fitness
|
23 |
|
24 |
# Settings
|
|
|
59 |
url = "https://ultralytics.com/assets/" + font.name
|
60 |
print(f'Downloading {url} to {font}...')
|
61 |
torch.hub.download_url_to_file(url, str(font), progress=False)
|
62 |
+
try:
|
63 |
+
return ImageFont.truetype(str(font), size)
|
64 |
+
except TypeError:
|
65 |
+
check_requirements('Pillow>=8.4.0') # known issue https://github.com/ultralytics/yolov5/issues/5374
|
66 |
|
67 |
|
68 |
class Annotator:
|
|
|
324 |
plt.savefig(f, dpi=300)
|
325 |
|
326 |
|
327 |
+
@try_except # known issue https://github.com/ultralytics/yolov5/issues/5395
|
328 |
+
@Timeout(30) # known issue https://github.com/ultralytics/yolov5/issues/5611
|
329 |
def plot_labels(labels, names=(), save_dir=Path('')):
|
330 |
# plot dataset labels
|
331 |
print('Plotting labels... ')
|