Commit
•
8e94bf6
1
Parent(s):
25a7e1d
Add `user_config_dir('Ultralytics')` (#4715)
Browse files- utils/general.py +9 -0
- utils/plots.py +4 -6
utils/general.py
CHANGED
@@ -103,6 +103,15 @@ def get_latest_run(search_dir='.'):
|
|
103 |
return max(last_list, key=os.path.getctime) if last_list else ''
|
104 |
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
def is_docker():
|
107 |
# Is environment a Docker container?
|
108 |
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
|
|
103 |
return max(last_list, key=os.path.getctime) if last_list else ''
|
104 |
|
105 |
|
106 |
+
def user_config_dir(dir='Ultralytics'):
|
107 |
+
# Return path of user configuration directory (make if necessary)
|
108 |
+
settings = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'}
|
109 |
+
path = Path.home() / settings.get(platform.system(), '') / dir
|
110 |
+
if not path.is_dir():
|
111 |
+
path.mkdir() # make dir if required
|
112 |
+
return path
|
113 |
+
|
114 |
+
|
115 |
def is_docker():
|
116 |
# Is environment a Docker container?
|
117 |
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
|
utils/plots.py
CHANGED
@@ -16,16 +16,14 @@ import seaborn as sn
|
|
16 |
import torch
|
17 |
from PIL import Image, ImageDraw, ImageFont
|
18 |
|
19 |
-
from utils.general import is_ascii,
|
20 |
from utils.metrics import fitness
|
21 |
|
22 |
# Settings
|
|
|
23 |
matplotlib.rc('font', **{'size': 11})
|
24 |
matplotlib.use('Agg') # for writing to files only
|
25 |
|
26 |
-
FILE = Path(__file__).absolute()
|
27 |
-
ROOT = FILE.parents[1] # yolov5/ dir
|
28 |
-
|
29 |
|
30 |
class Colors:
|
31 |
# Ultralytics color palette https://ultralytics.com/
|
@@ -49,9 +47,9 @@ colors = Colors() # create instance for 'from utils.plots import colors'
|
|
49 |
|
50 |
|
51 |
def check_font(font='Arial.ttf', size=10):
|
52 |
-
# Return a PIL TrueType Font, downloading to
|
53 |
font = Path(font)
|
54 |
-
font = font if font.exists() else (
|
55 |
try:
|
56 |
return ImageFont.truetype(str(font) if font.exists() else font.name, size)
|
57 |
except Exception as e: # download if missing
|
|
|
16 |
import torch
|
17 |
from PIL import Image, ImageDraw, ImageFont
|
18 |
|
19 |
+
from utils.general import user_config_dir, is_ascii, xywh2xyxy, xyxy2xywh
|
20 |
from utils.metrics import fitness
|
21 |
|
22 |
# Settings
|
23 |
+
CONFIG_DIR = user_config_dir() # Ultralytics settings dir
|
24 |
matplotlib.rc('font', **{'size': 11})
|
25 |
matplotlib.use('Agg') # for writing to files only
|
26 |
|
|
|
|
|
|
|
27 |
|
28 |
class Colors:
|
29 |
# Ultralytics color palette https://ultralytics.com/
|
|
|
47 |
|
48 |
|
49 |
def check_font(font='Arial.ttf', size=10):
|
50 |
+
# Return a PIL TrueType Font, downloading to CONFIG_DIR if necessary
|
51 |
font = Path(font)
|
52 |
+
font = font if font.exists() else (CONFIG_DIR / font.name)
|
53 |
try:
|
54 |
return ImageFont.truetype(str(font) if font.exists() else font.name, size)
|
55 |
except Exception as e: # download if missing
|