ultralytics/yolov5 · error · RuntimeError

{prefix}Error loading data from {path}: {e}\n{HELP_URL}

Error message

{prefix}Error loading data from {path}: {e}\n{HELP_URL}

What it means

LoadImages wraps any exception during path scanning — including the FileNotFoundError of error [15] and the 'No images found' assert — into a RuntimeError that appends the YOLOv5 dataset HELP_URL. It is the single failure surface for 'your data yaml points at nothing usable': the inner message {e} names the concrete problem (missing path, zero images after filtering, unreadable txt) while the wrapper adds remediation docs.

Source

Thrown at utils/dataloaders.py:524

            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, total
        if exists and LOCAL_RANK in {-1, 0}:
            d = f"Scanning {cache_path}... {nf} images, {nm + ne} backgrounds, {nc} corrupt"
            LOGGER.info(prefix + d)  # display cache results
            if cache["msgs"]:
                LOGGER.info("\n".join(cache["msgs"]))  # display warnings

View on GitHub (pinned to 20d1d78a08)

Solutions

  1. Read the inner exception text: '{prefix}{p} does not exist' means fix the path; 'No images found' means fix the file extensions/locations.
  2. Download or relink the dataset so the yaml train/val paths exist (they resolve relative to the yaml's directory).
  3. Confirm the directory actually contains supported extensions (jpg/png/bmp...).
  4. Consult the HELP_URL printed in the message for dataset layout documentation.

Example fix

# before
python train.py --data mydata.yaml ...  # val path missing -> RuntimeError('Error loading data from ...')

# after
# create/point val correctly, e.g. download: https://... and rerun so autodownload fills DATASETS_DIR
python train.py --data mydata.yaml ...
Defensive patterns

Strategy: try-catch

Validate before calling

from pathlib import Path
import yaml

def yaml_targets_resolve(data_yaml: str) -> bool:
    p = Path(data_yaml).resolve()
    d = yaml.safe_load(p.read_text())
    base = Path(d.get('path') or p.parent)
    ok = True
    for key in ('train', 'val', 'test'):
        v = d.get(key)
        if not v:
            continue
        for x in (v if isinstance(v, list) else [v]):
            target = Path(x) if str(x).startswith('/') else base / x
            ok &= target.exists()
    return ok

Try / catch

try:
    dataset = LoadImages(img_path, imgsz, ...)
except RuntimeError as e:
    if 'Error loading data from' in str(e):
        # inner exception names the dead path; check yaml paths and dataset presence
        raise SystemExit(f'fix data yaml paths: {e}') from e

Prevention

When it happens

Trigger: train.py/val.py with a data yaml whose train/val paths do not exist (inner [15] fires); a directory that exists but contains no files with image extensions (assert 'No images found'); a .txt manifest with zero valid lines; permission errors opening the txt file.

Common situations: Fresh clones without datasets; renamed dataset roots; yaml files copied between projects whose relative bases differ; uppercase extensions are handled, but unsupported formats (e.g. .jpeg2000) are filtered to zero.

Related errors


AI-assisted analysis of ultralytics/yolov5@20d1d78a08 (2026-08-15). Data as JSON: /api/errors/fbf42e0db42c6201. Report an issue: GitHub.