Skip to content

Commit 7c6a335

Browse files
fix: add default PIL font as fallback (#7010)
* 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 <Maximilian.Strobel@infineon.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
1 parent 3f634d4 commit 7c6a335

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

utils/plots.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
from copy import copy
99
from pathlib import Path
10+
from urllib.error import URLError
1011

1112
import cv2
1213
import matplotlib
@@ -55,11 +56,13 @@ def check_pil_font(font=FONT, size=10):
5556
try:
5657
return ImageFont.truetype(str(font) if font.exists() else font.name, size)
5758
except Exception: # download if missing
58-
check_font(font)
5959
try:
60+
check_font(font)
6061
return ImageFont.truetype(str(font), size)
6162
except TypeError:
6263
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()
6366

6467

6568
class Annotator:

0 commit comments

Comments
 (0)