ultralytics/yolov5 · error · FileNotFoundError
{prefix}{p} does not exist
Error message
{prefix}{p} does not exist What it means
LoadImages (utils/dataloaders.py) raises FileNotFoundError with a dataset prefix when a path entry from the data yaml / input list is neither an existing directory nor an existing file. This is the training/validation image-list builder: it accepts a directory, an image file, or a .txt listing images, and rejects anything else. The error is immediately re-wrapped by the except into the RuntimeError of error [16], so this message appears as the inner cause.
Source
Thrown at utils/dataloaders.py:519
self.stride = stride
self.path = path
self.albumentations = Albumentations(size=img_size) if augment else None
try:
f = [] # image files
for p in path if isinstance(path, list) else [path]:
p = Path(p) # os-agnostic
if p.is_dir(): # dir
f += glob.glob(str(p / "**" / "*.*"), recursive=True)
# f = list(p.rglob('*.*')) # pathlib
elif p.is_file(): # file
with open(p) as t:
t = t.read().strip().splitlines()
parent = str(p.parent) + os.sep
f += [x.replace("./", parent, 1) if x.startswith("./") else x for x in t] # to global path
# f += [p.parent / x.lstrip(os.sep) for x in t] # to global path (pathlib)
else:
raise FileNotFoundError(f"{prefix}{p} does not exist")
self.im_files = sorted(x.replace("/", os.sep) for x in f if x.split(".")[-1].lower() in IMG_FORMATS)
# self.img_files = sorted([x for x in f if x.suffix[1:].lower() in IMG_FORMATS]) # pathlib
assert self.im_files, f"{prefix}No images found"
except Exception as e:
raise RuntimeError(f"{prefix}Error loading data from {path}: {e}\n{HELP_URL}") from e
# Check cache
self.label_files = img2label_paths(self.im_files) # labels
cache_path = (p if p.is_file() else Path(self.label_files[0]).parent).with_suffix(".cache")
try:
cache, exists = np.load(cache_path, allow_pickle=True).item(), True # load dict
assert cache["version"] == self.cache_version # matches current version
assert cache["hash"] == get_hash(self.label_files + self.im_files) # identical hash
except Exception:
cache, exists = self.cache_labels(cache_path, prefix), False # run cache ops
# Display cache
nf, nm, ne, nc, n = cache.pop("results") # found, missing, empty, corrupt, totalView on GitHub (pinned to 20d1d78a08)
Solutions
- Download the dataset first (let check_dataset autodownload via the yaml 'download:' field, or fetch manually).
- Fix the yaml paths to actual locations — check them with Path(yaml_path).parent / train_path existence from the yaml's directory.
- If the dataset is present, correct the relative base: paths in the yaml are resolved relative to the yaml file's parent.
Example fix
# before (data.yaml): val: /mnt/nfs/coco/val2017 # not mounted # after (data.yaml): val: ../datasets/coco/val2017 # exists next to the yaml
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
def dataset_paths_exist(data_yaml: str) -> bool:
import yaml
p = Path(data_yaml).resolve()
d = yaml.safe_load(p.read_text())
base = Path(d.get('path') or p.parent)
for key in ('train', 'val'):
entry = d.get(key)
if entry is None:
continue
for x in (entry if isinstance(entry, list) else [entry]):
if not (base / x if not str(x).startswith('/') else Path(x)).exists():
return False
return True Prevention
- Run a path-existence check on data yaml entries before launching multi-hour training.
- Keep datasets and yamls together so relative resolution stays stable.
When it happens
Trigger: data yaml 'train: ../coco/train2017.txt' when that txt is absent; 'val: /datasets/coco/val2017' directory not yet downloaded or moved; a txt list whose parent-relative entries resolve to nothing (this check is on the list file itself, not its contents); wrong relative base when the yaml lives elsewhere.
Common situations: First runs before the dataset is downloaded; datasets relocated after yaml creation; sharing yamls across machines with different mounts; paths written on Windows and run on Linux.
Related errors
- {prefix}Error loading data from {path}: {e}\n{HELP_URL}
- {p} does not exist
- Dataset not found ❌
- Source path '{source}' does not exist
- More than one yaml file was found in the dataset root, canno
AI-assisted analysis of ultralytics/yolov5@20d1d78a08 (2026-08-15).
Data as JSON: /api/errors/eced04e89408ec92.
Report an issue: GitHub.