一、找到配置文件
YOLOv8 会将第一次运行的位置当做默认位置,此后不管将 ultralytics 移动到何处,训练时都将在第一次运行的位置寻找数据集并且将训练结果存储在与数据集同级的目录下。而且很难找到改变路径的方法,其实 YOLOv8 的配置文件隐藏地很深。
在 ...\ultralytics\ultralytics\utils 下有 _init_.py 文件,其中指明了 YOLOv8 的数据集配置文件的存放位置,不同的操作系统有不同的位置。
def get_user_config_dir(sub_dir='Ultralytics'):
"""
Get the user config directory.
Args:
sub_dir (str): The name of the subdirectory to create.
Returns:
(Path): The path to the user config directory.
"""
# Return the appropriate config directory for each operating system
if WINDOWS:
path = Path.home() / 'AppData' / 'Roaming' / sub_dir
elif MACOS: # macOS
path = Path.home() / 'Library' / 'Application Support' / sub_dir
elif LINUX:
path = Path.home() / '.config' / sub_dir
else:
raise ValueError(f'Unsupported operating system: {platform.system()}')
# GCP and AWS lambda fix, only /tmp is writeable
if not is_dir_writeable(path.parent):
LOGGER.warning(f"WARNING ⚠️ user config directory '{path}' is not writeable, defaulting to '/tmp' or CWD."
'Alternatively you can define a YOLO_CONFIG_DIR environment variable for this path.')
path = Path('/tmp') / sub_dir if is_dir_writeable('/tmp') else Path().cwd() / sub_dir
# Create the subdirectory if it does not exist
path.mkdir(parents=True, exist_ok=True)
return path
在不同的操作系统上运行以下代码即可知 Path.home() 位置
from pathlib import Path
print(Path.home())
而 sub_dir 代表 Ultralytics,因此,YOLOv8 配置文件所在目录位置就可以得到了
二、改变默认路径
用记事本打开 settings.yaml 文件,根据需要改变 datasets_dir,weights_dir,runs_dir 的位置,注意 runs 和 weights 虽然同级但 weights 在 runs 目录里面
settings_version: 0.0.4
datasets_dir: d:\workspace\YOLO\datasets
weights_dir: d:\workspace\YOLO\ultralytics\weights
runs_dir: d:\workspace\YOLO\ultralytics\runs
uuid: 8eb12fdc5b3a26c6990d9efa92c6935cb9e777d326b05db0011294e1430d9816
sync: true
api_key: ''
clearml: true
comet: true
dvc: true
hub: true
mlflow: true
neptune: true
raytune: true
tensorboard: true
wandb: true