[BUG] inference.py expects labeled subfolders in the --data-dir folder

Author: JosuaRiederCreated Nov 4, 2024Updated Aug 1, 2026
Labelsbug

Describe the bug When running inference.py --data-dir data --class-map class_map.txt --model efficientnet_b7 --num-classes 8 --checkpoint output/model_best.pth.tar where data is a directory that contains images and no subfolders, the script crashes with the following output:

Traceback (most recent call last):
  File "/home/josua/redacted/pytorch-image-models/inference.py", line 369, in <module>
    main()
  File "/home/josua/redacted/pytorch-image-models/inference.py", line 224, in main
    dataset = create_dataset(
              ^^^^^^^^^^^^^^^
  File "/home/josua/redacted/pytorch-image-models/timm/data/dataset_factory.py", line 216, in create_dataset
    ds = ImageDataset(
         ^^^^^^^^^^^^^
  File "/home/josua/redacted/pytorch-image-models/timm/data/dataset.py", line 36, in __init__
    reader = create_reader(
             ^^^^^^^^^^^^^^
  File "/home/josua/redacted/pytorch-image-models/timm/data/readers/reader_factory.py", line 44, in create_reader
    reader = ReaderImageFolder(root, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/josua/redacted/pytorch-image-models/timm/data/readers/reader_image_folder.py", line 82, in __init__
    raise RuntimeError(
RuntimeError: Found 0 images in subfolders of /home/josua/redacted/data/unlabeled. Supported image extensions are .png, .jpg, .jpeg

Expected behavior Instead of raising an error, I expect it to perform the inference on the (recursive) contents of data irrespective of the existence of labeled subfolders because labels are not necessary for inference.

Desktop (please complete the following information):

  • OS: x86_64 Linux 6.11.5-arch1-1
  • This repository version: d4dde48d
  • PyTorch version w/ CUDA/cuDNN: python-pytorch-cuda 2.3.1-8, cuda 12.6.2-2

Additional context Workaround: It works when, instead of placing the images in data/ directly, one places them in data/random_label/ where random_label is a random label, i.e. a random line from class_map.txt

Source: huggingface/pytorch-image-models