huggingface/pytorch-image-models · critical · RuntimeError

Found 0 images in subfolders of {root}. Supported image exte

Error message

Found 0 images in subfolders of {root}. Supported image extensions are {", ".join(get_img_extensions())}

What it means

ImageDataset (image_folder reader) walks root for image files under class subfolders and found zero usable samples, so it raises RuntimeError at construction — an empty dataset would otherwise fail confusingly during training.

Source

Thrown at timm/data/readers/reader_image_folder.py:82

            class_map='',
            input_key=None,
    ):
        super().__init__()

        self.root = root
        class_to_idx = None
        if class_map:
            class_to_idx = load_class_map(class_map, root)
        find_types = None
        if input_key:
            find_types = input_key.split(';')
        self.samples, self.class_to_idx = find_images_and_targets(
            root,
            class_to_idx=class_to_idx,
            types=find_types,
        )
        if len(self.samples) == 0:
            raise RuntimeError(
                f'Found 0 images in subfolders of {root}. '
                f'Supported image extensions are {", ".join(get_img_extensions())}')

    def __getitem__(self, index):
        path, target = self.samples[index]
        return open(path, 'rb'), target

    def __len__(self):
        return len(self.samples)

    def _filename(self, index, basename=False, absolute=False):
        filename = self.samples[index][0]
        if basename:
            filename = os.path.basename(filename)
        elif not absolute:
            filename = os.path.relpath(filename, self.root)
        return filename

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Verify root is the directory containing class-name subfolders, each holding images.
  2. Check extensions against timm.data.readers.get_img_extensions(); rename .JPG/.JPEG files or add extensions via set_img_extensions if needed.
  3. Confirm the path is mounted/accessible and not empty (ls root/*/ | head).
  4. If data lives in .tar shards, use the in_tar or wds reader instead.

Example fix

# before
ds = ImageDataset('/data/train_flat')  # images directly in dir

# after
# /data/train/dog/*.jpg, /data/train/cat/*.jpg
ds = ImageDataset('/data/train')
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
from timm.data.readers import get_img_extensions
imgs = [p for p in Path(root).rglob('*') if p.suffix.lower() in get_img_extensions()]
assert imgs, f'no images under {root}'
ds = ImageDataset(root)

Try / catch

try:
    ds = ImageDataset(root)
except RuntimeError as e:
    if 'Found 0 images' in str(e):
        raise SystemExit(f'check data path/layout: {root}')
    raise

Prevention

When it happens

Trigger: Calling ImageDataset(root) (or create_dataset with image_folder) where root has no class subdirectories containing files with supported extensions (jpg/jpeg/png/bmp/gif/webp/etc. per get_img_extensions).

Common situations: Wrong or misspelled data dir path; images stored flat in root without per-class folders; images with uppercase or unsupported extensions; dataset on an unmounted drive; passing a tar/WebDataset-style directory to the image_folder reader.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/3834caad64e4ed82. Report an issue: GitHub.