我院新闻
yolov8 路径问题
发布时间:2024-01-13

训练时,报错:data.yaml does not exist

!yolo task=detect mode=train model=yolov8n.pt data=data.yaml

解决办法:

写绝对路径:

!yolo task=detect mode=train model=yolov8n.pt data=/home/{username}/{xxx}/{xxx}/datasets/data.yaml

data.ymal 里path的配置也要是绝对路径:

# path: ../datasets/{your_project}  # dataset root dir
path: /home/{username}/{xxx}/{xxx}/datasets/{your_project}  # dataset root dir

原因

  1. cli 传参
    https://github.com/ultralytics/ultralytics/blob/790f9c067c9a3548acf7c6925cea14de9ad77787/ultralytics/yolo/cfg/__init__.py#L183

  2. train
    https://github.com/ultralytics/ultralytics/blob/790f9c067c9a3548acf7c6925cea14de9ad77787/ultralytics/yolo/engine/model.py#L294

  3. 初始化trainer
    https://github.com/ultralytics/ultralytics/blob/790f9c067c9a3548acf7c6925cea14de9ad77787/ultralytics/yolo/engine/trainer.py#L75

  4. 获取参数
    https://github.com/ultralytics/ultralytics/blob/790f9c067c9a3548acf7c6925cea14de9ad77787/ultralytics/yolo/cfg/__init__.py#L87

  5. 加载data.ymal
    https://github.com/ultralytics/ultralytics/blob/790f9c067c9a3548acf7c6925cea14de9ad77787/ultralytics/yolo/engine/trainer.py#L122

  6. 拼接data.ymal 文件路径
    https://github.com/ultralytics/ultralytics/blob/790f9c067c9a3548acf7c6925cea14de9ad77787/ultralytics/yolo/data/utils.py#L220

    这里可以看到,如果不写成绝对路径,则按DATASETS_DIR去拼接,
    过程是:yolo先找到user_config_dir
    /home/{user}/.config,
    第一次运行yolo项目A时,会在下面创建/home/{user}/.config/Ultralytics
    和/home/{user}/.config/Ultralytics/settings.yaml
    setting.ymal 里会有DATASETS_DIR,值就是项目A的datasets路径。

datasets_dir: /home/{user}/{projectA}/datasets

[返回上级]