Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JosuaRieder opened this issue Nov 4, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@JosuaRieder
Copy link
Contributor

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: d4dde48
  • 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

@JosuaRieder JosuaRieder added the bug Something isn't working label Nov 4, 2024
@rwightman
Copy link
Collaborator

@JosuaRieder it works just fine, the issue is using the class map filters by folder label structure to match behaviour where subsets of imagenet are remapped using class map. Class map isn't really intended to provide labels, it's remapping/filtering transform.

@JosuaRieder
Copy link
Contributor Author

It seems I have misunderstood the intended purpose of class map (as I wrote in the PR).

Even so, I think it's unexpected that inference.py requires a different --data-dir structure with and without class map. I don't see the purpose of having/requiring this subfolder structure when inferring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants