yolov8训练自定义数据集——settings.yaml与自定义数据集.yaml指向路径的配置问题

摘要

如果你在调用模型预测后找不到预测后的结果存放路径,如果你在训练模型时出现找不到数据集存放位置,都可以来这里寻找答案
找不到数据集的报错可能如下:

RuntimeError: Dataset 'csgo.yaml' error ❌ 
Dataset 'xxx.yaml' images not found ⚠️, missing path '/root/tmp/xxxx'
Note dataset download directory is '/root/'. You can update this in '/root/.config/Ultralytics/settings.yaml'

一、yolov8中与数据集有关的文件

  1. settings文件
  2. 自定义数据集时需要编写的.yaml文件

二、settings文件

(一)settings文件的参数信息

在这里插入图片描述实际例子
在这里插入图片描述

(二)如何查看

yolo官网
可以使用以下代码查看settings文件的参数信息

from ultralytics import settings

# View all settings
print(settings)

# Return a specific setting
value = settings['runs_dir']

也可以在终端使用

yolo settings

(三)如何修改

1、python代码修改
from ultralytics import settings

# Update a setting
settings.update({'runs_dir': '/path/to/runs'})

# Update multiple settings
settings.update({'runs_dir': '/path/to/runs', 'tensorboard': False})

# Reset settings to default values
settings.reset()
2、终端修改
# Update a setting
yolo settings runs_dir='/path/to/runs'

# Update multiple settings
yolo settings runs_dir='/path/to/runs' tensorboard=False

# Reset settings to default values
yolo settings reset
3、找到文件所在位置直接编辑

在 …\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

在不同的操作系统中均可以使用以下代码查找到路径信息

from pathlib import Path
 
print(Path.home())

依照路径和代码中的信息即可找到settings文件

三 训练自定义数据集需要创建的.yaml文件

(一).yaml文件的格式

1、这是官方格式
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/coco8-pose  # dataset root dir
train: images/train  # train images (relative to 'path') 4 images
val: images/val  # val images (relative to 'path') 4 images
test:  # test images (optional)

# Keypoints
kpt_shape: [17, 3]  # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible)
# 共有多少个关键点,维度是多少
flip_idx: [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]
# 反转后关键点的对应关系

# Classes dictionary
names:
  0: person

如果维度为2

<class-index> <x> <y> <width> <height> <px1> <py1> <px2> <py2> ... <pxn> <pyn>
# 采用这种格式、 <class-index> 是对象的类索引、<x> <y> <width> <height> 是边界框的坐标及宽和高,而 <px1> <py1> <px2> <py2> ... <pxn> <pyn> 是关键点的像素坐标。坐标之间用空格隔开。

如果维度为3

<class-index> <x> <y> <width> <height> <px1> <py1> <p1-visibility> <px2> <py2> <p2-visibility> <pxn> <pyn> <p2-visibility>
<pn-visibility>:0代表不可见、1代表遮挡、2代表可见
2、可能的修改

如:

RuntimeError: Dataset 'csgo.yaml' error ❌ 
Dataset 'xxx.yaml' images not found ⚠️, missing path '/root/tmp/xxxx'
Note dataset download directory is '/root/'. You can update this in '/root/.config/Ultralytics/settings.yaml'

所以如果你严格按照官方路径填写而报错,你可以将它修改为绝对路径
例如:
在这里插入图片描述
在此时settings文件的配置如图
在这里插入图片描述

  • 13
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值