Unverified 提交 8e94bf62 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Add `user_config_dir('Ultralytics')` (#4715)

* Add `user_config_dir` * Linux to .config
上级 25a7e1da
...@@ -103,6 +103,15 @@ def get_latest_run(search_dir='.'): ...@@ -103,6 +103,15 @@ def get_latest_run(search_dir='.'):
return max(last_list, key=os.path.getctime) if last_list else '' 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(): def is_docker():
# Is environment a Docker container? # Is environment a Docker container?
return Path('/workspace').exists() # or Path('/.dockerenv').exists() return Path('/workspace').exists() # or Path('/.dockerenv').exists()
......
...@@ -16,16 +16,14 @@ import seaborn as sn ...@@ -16,16 +16,14 @@ import seaborn as sn
import torch import torch
from PIL import Image, ImageDraw, ImageFont 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 from utils.metrics import fitness
# Settings # Settings
CONFIG_DIR = user_config_dir() # Ultralytics settings dir
matplotlib.rc('font', **{'size': 11}) matplotlib.rc('font', **{'size': 11})
matplotlib.use('Agg') # for writing to files only matplotlib.use('Agg') # for writing to files only
FILE = Path(__file__).absolute()
ROOT = FILE.parents[1] # yolov5/ dir
class Colors: class Colors:
# Ultralytics color palette https://ultralytics.com/ # Ultralytics color palette https://ultralytics.com/
...@@ -49,9 +47,9 @@ colors = Colors() # create instance for 'from utils.plots import colors' ...@@ -49,9 +47,9 @@ colors = Colors() # create instance for 'from utils.plots import colors'
def check_font(font='Arial.ttf', size=10): 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 = Path(font)
font = font if font.exists() else (ROOT / font.name) font = font if font.exists() else (CONFIG_DIR / font.name)
try: try:
return ImageFont.truetype(str(font) if font.exists() else font.name, size) return ImageFont.truetype(str(font) if font.exists() else font.name, size)
except Exception as e: # download if missing except Exception as e: # download if missing
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论