Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user_config_dir('Ultralytics') #4715

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def get_latest_run(search_dir='.'):
return max(last_list, key=os.path.getctime) if last_list else ''


def user_config_dir(dir='Ultralytics'):
# Return path of user configuration directory (make if necessary)
settings = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'}
path = Path.home() / settings.get(platform.system(), '') / dir
if not path.is_dir():
path.mkdir() # make dir if required
return path


def is_docker():
# Is environment a Docker container?
return Path('/workspace').exists() # or Path('/.dockerenv').exists()
Expand Down
10 changes: 4 additions & 6 deletions utils/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
import torch
from PIL import Image, ImageDraw, ImageFont

from utils.general import is_ascii, xyxy2xywh, xywh2xyxy
from utils.general import user_config_dir, is_ascii, xywh2xyxy, xyxy2xywh
from utils.metrics import fitness

# Settings
CONFIG_DIR = user_config_dir() # Ultralytics settings dir
matplotlib.rc('font', **{'size': 11})
matplotlib.use('Agg') # for writing to files only

FILE = Path(__file__).absolute()
ROOT = FILE.parents[1] # yolov5/ dir


class Colors:
# Ultralytics color palette https://ultralytics.com/
Expand All @@ -49,9 +47,9 @@ def hex2rgb(h): # rgb order (PIL)


def check_font(font='Arial.ttf', size=10):
# Return a PIL TrueType Font, downloading to ROOT dir if necessary
# Return a PIL TrueType Font, downloading to CONFIG_DIR if necessary
font = Path(font)
font = font if font.exists() else (ROOT / font.name)
font = font if font.exists() else (CONFIG_DIR / font.name)
try:
return ImageFont.truetype(str(font) if font.exists() else font.name, size)
except Exception as e: # download if missing
Expand Down