maxstrobel Maximilian Strobel glenn-jocher commited on
Commit
7c6a335
·
unverified ·
1 Parent(s): 3f634d4

fix: add default PIL font as fallback (#7010)

Browse files

* fix: add default font as fallback

Add default font as fallback if the downloading of the Arial.ttf font
fails for some reason, e.g. no access to public internet.

* Update plots.py

Co-authored-by: Maximilian Strobel <[email protected]>
Co-authored-by: Glenn Jocher <[email protected]>

Files changed (1) hide show
  1. utils/plots.py +4 -1
utils/plots.py CHANGED
@@ -7,6 +7,7 @@ import math
7
  import os
8
  from copy import copy
9
  from pathlib import Path
 
10
 
11
  import cv2
12
  import matplotlib
@@ -55,11 +56,13 @@ def check_pil_font(font=FONT, size=10):
55
  try:
56
  return ImageFont.truetype(str(font) if font.exists() else font.name, size)
57
  except Exception: # download if missing
58
- check_font(font)
59
  try:
 
60
  return ImageFont.truetype(str(font), size)
61
  except TypeError:
62
  check_requirements('Pillow>=8.4.0') # known issue https://github.com/ultralytics/yolov5/issues/5374
 
 
63
 
64
 
65
  class Annotator:
 
7
  import os
8
  from copy import copy
9
  from pathlib import Path
10
+ from urllib.error import URLError
11
 
12
  import cv2
13
  import matplotlib
 
56
  try:
57
  return ImageFont.truetype(str(font) if font.exists() else font.name, size)
58
  except Exception: # download if missing
 
59
  try:
60
+ check_font(font)
61
  return ImageFont.truetype(str(font), size)
62
  except TypeError:
63
  check_requirements('Pillow>=8.4.0') # known issue https://github.com/ultralytics/yolov5/issues/5374
64
+ except URLError: # not online
65
+ return ImageFont.load_default()
66
 
67
 
68
  class Annotator: