ultralytics/ultralytics · critical · RuntimeError

No images from {self.json_file} found in {self.img_path}. {H

Error message

No images from {self.json_file} found in {self.img_path}. {HELP_URL}

What it means

Raised by the JSON-backed dataset used for open-vocabulary training (YOLOE-style) when get_labels finds the cached 'labels' list empty after scanning the COCO-format JSON annotation file. Empty labels means the scan matched zero images between the JSON annotations and the image directory (self.img_path), i.e. no image referenced in the JSON could be located on disk.

Source

Thrown at ultralytics/data/dataset.py:795

                f"{self.json_file}: ignored segmentations that are not polygon point lists, such as RLE masks. "
                "Annotations left without a polygon use a segment shaped like their bounding box."
            )
        x["hash"] = self.get_cache_hash()
        save_dataset_cache_file(self.prefix, path, x, DATASET_CACHE_VERSION)
        return x

    def get_labels(self) -> list[dict]:
        """Load labels from cache or generate them from JSON file.

        Returns:
            (list[dict]): List of label dictionaries, each containing information about an image and its annotations.
        """
        cache_path = Path(self.json_file).with_suffix(".cache")
        cache, _ = self._load_or_scan_cache(cache_path, self.get_cache_hash())
        [cache.pop(k) for k in ("hash", "version")]  # remove items
        labels = cache["labels"]
        if not labels:
            raise RuntimeError(f"No images from {self.json_file} found in {self.img_path}. {HELP_URL}")
        if not any(label["texts"] for label in labels):  # category_freq is empty, so negative texts cannot be built
            raise RuntimeError(
                f"No annotations in {self.json_file} survived filtering. Every one is iscrowd, resolves to an empty "
                f"caption span or has a zero-size box. {HELP_URL}"
            )
        self._verify_instance_counts(labels)
        self.im_files = [str(label["im_file"]) for label in labels]
        if LOCAL_RANK in {-1, 0}:
            LOGGER.info(f"Load {self.json_file} from cache file {cache_path}")
        return labels

    def build_transforms(self, hyp: dict | None = None) -> Compose:
        """Configure augmentations for training with optional text loading.

        Args:
            hyp (dict, optional): Hyperparameters for transforms.

        Returns:

View on GitHub (pinned to 0449ea011c)

Solutions

  1. Verify img_path actually contains the images listed in the JSON: cross-check a few images[i].file_name values against directory listings.
  2. If file_name entries include subdirectories, point img_path at their true common parent so file_name resolves relative to it.
  3. Re-download or re-extract the image set matching the annotation file version (COCO 2014 vs 2017 files are not interchangeable).
  4. Delete the <json>.cache file so the scan re-runs after correcting paths.

Example fix

# before
YOLOE("yoloe-v8s.pt").train(data={"json_file": "instances_val2017.json", "img_path": "val_empty_dir"})

# after
YOLOE("yoloe-v8s.pt").train(data={"json_file": "instances_val2017.json", "img_path": "coco/val2017"})
Defensive patterns

Strategy: validation

Validate before calling

import json
from pathlib import Path

def json_images_present(json_file: str, img_path: str) -> bool:
    names = {Path(im["file_name"]).name for im in json.load(open(json_file))["images"]}
    on_disk = {p.name for p in Path(img_path).iterdir()}
    return bool(names) and names <= on_disk

Prevention

When it happens

Trigger: Constructing this dataset (via YOLOE/open-vocabulary training with json_file and img_path) where the file names or relative paths inside the JSON's images[] entries do not correspond to any files under img_path — e.g. 'file_name': '000000123.jpg' but the directory holds '123.png', or img_path points at the wrong split directory.

Common situations: Wrong img_path (train images dir given for a val JSON), dataset extracted with renamed files, COCO file_name values that include a subpath ('images/train/x.jpg') that does not exist relative to img_path, or case-sensitivity mismatches after copying from macOS/Windows to Linux.

Related errors


AI-assisted analysis of ultralytics/ultralytics@0449ea011c (2026-08-15). Data as JSON: /api/errors/47913f74ac02588b. Report an issue: GitHub.